Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.visual.basic    |    MS Visual Basic discussions, NOT dot-net    |    10,840 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 10,509 of 10,840    |
|    Otis to Tom    |
|    Re: Example of connecting VB6 to Excell    |
|    01 Sep 07 16:35:58    |
      XPost: comp.lang.basic.visual.misc       From: otie_nospam@cox.net              This is not what you asked for, but it is all I have. It might help:              Private Sub grdOutput_MouseUp(Button As Integer, Shift As Integer, x As       Single, y As Single)        Dim x1%, y1%        Dim current_col%, current_row%        Dim col_to_write%, row_to_write%        Dim current_excel_column_width%               If Button = 1 Then        Dim MyXL As Object ' Variable to hold reference to       Microsoft Excel.        Dim ExcelWasNotRunning As Boolean ' Flag for final release.        Dim mySheet As Excel.Worksheet               'test to see if there is a copy of Microsoft Excel already running.        On Error Resume Next ' Defer error trapping.               'getobject function called without the first argument returns a       reference to an instance of the application. If the application isn't       running, an error occurs.        Set MyXL = GetObject(, "Excel.Application")        If Err.Number <> 0 Then        ExcelWasNotRunning = True        MsgBox "Please open an Excel spreadsheet before performing       this operation.", vbCritical, "No spreadsheet open"        Set mySheet = Nothing        Set MyXL = Nothing        Exit Sub        End If               Err.Clear ' Clear Err object in case error       occurred.               Set mySheet = MyXL.Application.ActiveSheet               'show Microsoft Excel through its Application property. Then       show the actual window containing the file using the Windows collection       of the MyXL object reference.        MyXL.Application.Visible = True        MyXL.Parent.Windows(1).Visible = True               'get active cell - this is where program will start to copy data        current_col% = MyXL.Application.ActiveCell.Column - 1        current_row% = MyXL.Application.ActiveCell.Row - 1               'set centering        For y1% = 1 To grdOutput.Cols        mySheet.Columns(y1% + current_col%).HorizontalAlignment =       xlCenter        Next y1%               current_excel_column_width% = excel_column_width%               mySheet.Application.ActiveWorkbook.Colors(50) = clr_light_rose        mySheet.Application.ActiveWorkbook.Colors(51) = clr_light_blue               'copy data - each column, then each row - from a grid - into Excel        For y1% = 1 To grdOutput.Rows - 1        grdOutput.Row = y1%        row_to_write% = y1% + current_row%               For x1% = 0 To grdOutput.Cols - 1        col_to_write% = x1% + 1 + current_col%        grdOutput.Col = x1%               With mySheet.Cells(row_to_write%, col_to_write%)        .Font.Name = "Arial"        .Font.Color = grdOutput.CellForeColor        .Font.Bold = grdOutput.CellFontBold        .Font.Italic = grdOutput.CellFontItalic        .Value = grdOutput.Text               If grdOutput.CellBackColor = clr_light_rose Then        mySheet.Cells(row_to_write%,       col_to_write%).Interior.ColorIndex = 50        ElseIf grdOutput.CellBackColor = clr_light_blue Then        mySheet.Cells(row_to_write%,       col_to_write%).Interior.ColorIndex = 51        End If        End With        Next x1%        Next y1%       'done              user_cancel:        'if this copy of Microsoft Excel was not running when you       started, close it using the Application property's Quit method.        'note that when you try to quit Microsoft Excel, the title bar       blinks and a message is displayed asking if you want to save any loaded       files.        If ExcelWasNotRunning = True Then        MyXL.Application.Quit        End If               Set mySheet = Nothing 'release resources        Set MyXL = Nothing        End If               excel_column_width% = current_excel_column_width%       End Sub                            Otis                     Tom wrote:       > Does anyone have a simple example of connecting to a spreadsheet, extracting       > some cells, and making a new spreadsheet with the extracted data; not just a       > new tab.       >       > Thanks in advance.       >       > Tom D.       >       >              --- SoupGate-Win32 v1.05        * Origin: you cannot sedate... all the things you hate (1:229/2)    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca