I have Access set up using VBA to run a bunch of queries automatically, and then export the results into Excel. The only problem is, I want each query to be exported to the same Excel File, but different worksheet.
What happens now is that a new Excel file is opened for each query (with the same name, as read-only) and then the data is imported into the correct worksheet number. I just need to figure out a way to have it all pasted into the same file!
The code that is responsible for this part is here I believe:
Expand|Select|Wrap|Line Numbers
- WorksheetToPlace = "Sheet" & WorksheetNumber
- Set App = CreateObject("Excel.Application") 'This opens excel application windows
- App.Visible = True
- Set File = App.Workbooks.Open("C:\Sessions\NumberOfSessions.xls") 'This opens your particular excel file (or workbook)
- Set ws = File.Worksheets(WorksheetToPlace) 'This opens your sheet that you want to write to
- ws.Activate
Thanks for your time!