' From the tools menu in Access, click References & check
' "Microsoft DAO x.x" and "Microsoft Excel x.0" Object
' library references.
Private Sub Command0_Click()
Dim dbCH As Database
Dim rsCH As DAO.Recordset
Dim CHApp As Excel.Application
Dim chws1 As Excel.worksheet
Set dbCH = CurrentDb
Set rsCH = dbCH.OpenRecordset("test_table2")
Set CHApp = New Excel.Application
CHApp.Visible = True
CHApp.Workbooks.Add
Set chws1 = CHApp.Workbooks(1).Worksheets(1)
chws1.Range("A1").Value = "Test"
chws1.Range("A2").CopyFromRecordset rsCH
chws1.SaveAs "C:\Test.xls"
Set chws1 = Nothing
CHApp.Workbooks(1).Close
CHApp.Quit
Set CHApp = Nothing
rsCH.Close
Set rsCH = Nothing
Set dbCH = Nothing
End Sub