bugsy
11-05-2007, 05:31 PM
Can this be done through a macro ?
If not, what would be a simple way to do this ?
thanks.
If not, what would be a simple way to do this ?
thanks.
|
View Full Version : Transferring 4 queries to 4 tabs of the same spreadsheet bugsy 11-05-2007, 05:31 PM Can this be done through a macro ? If not, what would be a simple way to do this ? thanks. Uncle Gizmo 11-06-2007, 08:34 AM When you say spreadsheet, I assume you mean datasheet displayed on a tab on a form? GaryPanic 11-06-2007, 08:38 AM 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 GaryPanic 11-06-2007, 08:49 AM 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 bugsy 11-06-2007, 09:04 AM 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: bugsy 11-06-2007, 09:25 AM 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 ? |