' Needs a reference to the "Microsoft Excel x.0 Object Library"
' from the Project menu > References options.
Private objXLApp As Excel.Application
Private Sub Form_Load()
' Use Late Binding Automation rather than the shell statement.
' This creates a "behind the scenes" instance of MsExcel.
Set objXLApp = New Excel.Application
With objXLApp
' Add a new workbook, then select the first sheet.
.Workbooks.Open "C:\Path\File.xls"
.Workbooks(1).Worksheets(1).Select
' Using the CopyFromRecordset() procedure built into Excel, paste
' your table into the first cell of the first worksheet.
.Worksheets(1).Range("A1").CopyFromRecordset YourRecordsetVariable
' Now show MsExcel to the user.
.Visible = True
' If you want, you can now save the workbook:
.Workbooks(1).SaveAs "C:\path\File.xls"
End With
End Sub
Private Sub Form_Unload(Cancel As Integer)
' If the instance of Excel we made is still open when this program is exited,
' close it & unload it's reference taken up in the computers memory.
If Not (objXLApp Is Nothing) Then
Set objXLApp = Nothing
End If
End Sub