scotton1982
New member
- Local time
- Today, 05:33
- Joined
- Jul 17, 2012
- Messages
- 1
Hi All,
I am really struggling with exporting a query into excel without saving. I am currently using the below code which exports the query into Excel without issue, the only issue I have is there is no field name/column heading exported across.
The below code does not include my many attempts at this, but gives you an idea of what I am trying to do:
Dim dbs As DAO.Database
Dim rstGetRecordSet As Recordset
Dim objXL As Object
Dim objCreateWkb As Object
Dim objActiveWkb As Object
Set dbs = CurrentDb
Set objXL = CreateObject("Excel.Application")
Set objCreateWkb = objXL.Workbooks.Add
Set objActiveWkb = objXL.Application.ActiveWorkBook
objXL.Visible = True
objActiveWkb.Sheets.Add
objActiveWkb.Worksheets(1).Name = "Photo Austria"
Set rstGetRecordSet = dbs.OpenRecordset("y_AT_02")
objActiveWkb.Worksheets("Photo Austria").Cells(2, 1).CopyFromRecordset rstGetRecordSet
objActiveWkb.Worksheets("Photo Austria").Columns("A:Z").EntireColumn.AutoFit
Set objActiveWkb = Nothing
Set objCreateWkb = Nothing
Set objXL = Nothing
rstGetRecordSet.Close
dbs.Close
Set rstGetRecordSet = Nothing
Set dbs = Nothing
I am really struggling with exporting a query into excel without saving. I am currently using the below code which exports the query into Excel without issue, the only issue I have is there is no field name/column heading exported across.
The below code does not include my many attempts at this, but gives you an idea of what I am trying to do:
Dim dbs As DAO.Database
Dim rstGetRecordSet As Recordset
Dim objXL As Object
Dim objCreateWkb As Object
Dim objActiveWkb As Object
Set dbs = CurrentDb
Set objXL = CreateObject("Excel.Application")
Set objCreateWkb = objXL.Workbooks.Add
Set objActiveWkb = objXL.Application.ActiveWorkBook
objXL.Visible = True
objActiveWkb.Sheets.Add
objActiveWkb.Worksheets(1).Name = "Photo Austria"
Set rstGetRecordSet = dbs.OpenRecordset("y_AT_02")
objActiveWkb.Worksheets("Photo Austria").Cells(2, 1).CopyFromRecordset rstGetRecordSet
objActiveWkb.Worksheets("Photo Austria").Columns("A:Z").EntireColumn.AutoFit
Set objActiveWkb = Nothing
Set objCreateWkb = Nothing
Set objXL = Nothing
rstGetRecordSet.Close
dbs.Close
Set rstGetRecordSet = Nothing
Set dbs = Nothing