To automate Excel from VB6....
VB Code:
  1. Option Explicit
  2. 'Add a reference to MS Excel xx.0 Object Library
  3. Private moApp As Excel.Application
  4.  
  5. Private Sub Command1_Click()
  6.     Dim oWB As Excel.Workbook
  7.    
  8.     moApp.Visible = True
  9.     Set oWB = moApp.Workbooks.Open("C:\Book1.xls")
  10.     oWB.Sheets(2).Activate
  11.     MsgBox "Last used row: " & oWB.Sheets(2).Cells.SpecialCells(xlCellTypeLastCell).Row
  12.     MsgBox "Contents: " & oWB.Sheets(2).Cells.SpecialCells(xlCellTypeLastCell).Value
  13.    
  14.     oWB.Close SaveChanges:=False
  15.     Set oWB = Nothing
  16. End Sub
  17.  
  18. Private Sub Form_Load()
  19.     Set moApp = New Excel.Application
  20. End Sub
  21.  
  22. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  23.     If TypeName(moApp) <> "Nothing" Then
  24.         moApp.Quit
  25.     End If
  26.     Set moApp = Nothing
  27. End Sub