Transferring 4 queries to 4 tabs of the same spreadsheet

bugsy

Registered User.
Local time
Today, 13:05
Joined
Oct 1, 2007
Messages
99
Can this be done through a macro ?

If not, what would be a simple way to do this ?

thanks.
 
If you mean into a spreadsheet and each qry goes to a seperate tab..
then thats do-able - if you look for a thread where I have ask this same question the answer is there - I will see I still have the code
 
found it
look under qry to excel - it will give you the full position on this but the code is _ look at what the guys (and Girls ) have helped me with and you will see the full story ensure that the right libary is selected -

"Hi Gary, i've inserted the code below in dark red."

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 = "Trash1"

Set rstGetRecordSet = dbs.OpenRecordset("Trash1")

objActiveWkb.Worksheets("Trash1").Cells(1, 1).CopyFromRecordset rstGetRecordSet

objActiveWkb.Sheets.Add
objActiveWkb.Worksheets(2).Name = "ABC"

Set rstGetRecordSet = dbs.OpenRecordset("ABC_Query_Name")

objActiveWkb.Worksheets("ABC").Cells(1, 1).CopyFromRecordset rstGetRecordSet

objActiveWkb.Worksheets(1).SaveAs FileName:="c:\trash.xls"

objActiveWkb.Close

Set objActiveWkb = Nothing
Set objCreateWkb = Nothing
Set objXL = Nothing
rstGetRecordSet.Close
dbs.Close
Set rstGetRecordSet = Nothing
Set dbs = Nothing
 
Thanks Gary

i put my query names; for some reason the first query is not creating, onle the second one :rolleyes:

and Column headings are gone :confused:
 
Hey, I have it creating 4 queries to 4 tabs, thank a lot.
Is there a way to include column headings ?

Also, can it be sent to a template ?
 

Users who are viewing this thread

Back
Top Bottom