G
GLENN
hi all,
I posted a request yesterday about how to export an
access2k query results to an Excel worksheet. Now That I
made some researches and found out the code to do this, I
still have one problem. How to export the query header to
the excel worksheet. Can someone please help.
The following is the code I use to export the query
results.
Private Sub Command0_Click()
Dim xlapp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlsheet1 As Excel.Worksheet
Dim db As Database
Dim rs As Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("qry_20+FBH", dbOpenSnapshot)
Set xlapp = CreateObject("excel.application")
With xlapp
.Visible = True
.WindowState = xlMinimized
End With
Set xlbook = xlapp.Workbooks.Add
xlbook.SaveAs FileName:="M:\MIS Caredays\kids20+_test.xls"
Set xlsheet1 = xlbook.Worksheets.Add
xlsheet1.Name = "20+FBH"
xlsheet1.Cells.CopyFromRecordset rs
xlsheet1.Cells.AutoFormat
xlsheet1.Cells.AutoFit
xlbook.Save
Set xlsheet1 = Nothing
Set xlbook = Nothing
Set xlapp = Nothing
rs.Close
Set rs = Nothing
End Sub
I posted a request yesterday about how to export an
access2k query results to an Excel worksheet. Now That I
made some researches and found out the code to do this, I
still have one problem. How to export the query header to
the excel worksheet. Can someone please help.
The following is the code I use to export the query
results.
Private Sub Command0_Click()
Dim xlapp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlsheet1 As Excel.Worksheet
Dim db As Database
Dim rs As Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("qry_20+FBH", dbOpenSnapshot)
Set xlapp = CreateObject("excel.application")
With xlapp
.Visible = True
.WindowState = xlMinimized
End With
Set xlbook = xlapp.Workbooks.Add
xlbook.SaveAs FileName:="M:\MIS Caredays\kids20+_test.xls"
Set xlsheet1 = xlbook.Worksheets.Add
xlsheet1.Name = "20+FBH"
xlsheet1.Cells.CopyFromRecordset rs
xlsheet1.Cells.AutoFormat
xlsheet1.Cells.AutoFit
xlbook.Save
Set xlsheet1 = Nothing
Set xlbook = Nothing
Set xlapp = Nothing
rs.Close
Set rs = Nothing
End Sub