To automate Excel from VB6....
VB Code:
Option Explicit 'Add a reference to MS Excel xx.0 Object Library Private moApp As Excel.Application Private Sub Command1_Click() Dim oWB As Excel.Workbook moApp.Visible = True Set oWB = moApp.Workbooks.Open("C:\Book1.xls") oWB.Sheets(2).Activate MsgBox "Last used row: " & oWB.Sheets(2).Cells.SpecialCells(xlCellTypeLastCell).Row MsgBox "Contents: " & oWB.Sheets(2).Cells.SpecialCells(xlCellTypeLastCell).Value oWB.Close SaveChanges:=False Set oWB = Nothing End Sub Private Sub Form_Load() Set moApp = New Excel.Application End Sub Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) If TypeName(moApp) <> "Nothing" Then moApp.Quit End If Set moApp = Nothing End Sub





Reply With Quote