Output query to excel

B

Bob

Hi,

Can anyone help me with outputing the results of a query to a particular
worksheet in an Excel workbook.
Using an "Output To" macro, I've managed to output my query to Excel so
that it replaces the whole .xls workbook.
But what I need to do is output to Sheet 1 of the .xls workbook and
leave Sheet 2 intact as it will have formulas referring to Sheet 1.

Thanks

Bob
 
F

fredg

Hi,

Can anyone help me with outputing the results of a query to a particular
worksheet in an Excel workbook.
Using an "Output To" macro, I've managed to output my query to Excel so
that it replaces the whole .xls workbook.
But what I need to do is output to Sheet 1 of the .xls workbook and
leave Sheet 2 intact as it will have formulas referring to Sheet 1.

Thanks

Bob

Look up the TransferSpreadsheet method in VBA help.

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9,
"QueryName", "c:\PathToFolder\FileName.xls", True

The above will add a new worksheet to the workbook named "QueryName".
You can use code within the workbook to then copy your data to
whatever sheet you wish, then delete the "QueryName" worksheet.

Change "QueryName" to whatever the actual name of your query is.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top