Exporting to excel

  • Thread starter Thread starter danijela.simunovic
  • Start date Start date
D

danijela.simunovic

Hi! I know how to export one query or table to excel. But is there a
way to export few tables or querys to one excel file but to different
sheets? So if i want to export 5 tables it would make 5 sheets in
excel. Any help would be great!

Danijela
 
Hi Danijela,

Try using DoCmd.TransferSpreadsheet instead of DoCmd.OutputTo, as in the
following example:

DoCmd.TransferSpreadsheet TransferType:=acExport, _
TableName:=strSourceName, Filename:=strFileName, _
HasFieldNames:=True

where strSourceName is a string variable that contains the name of the table
or query that you want to export, and strFileName is the complete path and
filename for the Excel file. You can do something like this:

Dim strFileName as String
strFileName = CurrentProject.Path & "\ExportedData.xls"

for a hardcoded Excel filename, or you can pass strFileName in as a
parameter to the subroutine or function:

strFileName = CurrentProject.Path & "\" & strFileName


Tom

http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________

:

Hi! I know how to export one query or table to excel. But is there a
way to export few tables or querys to one excel file but to different
sheets? So if i want to export 5 tables it would make 5 sheets in
excel. Any help would be great!

Danijela
 
Hi! I know how to export one query or table to excel. But is there a
way to export few tables or querys to one excel file but to different
sheets? So if i want to export 5 tables it would make 5 sheets in
excel. Any help would be great!

Danijela

From Access to Excel?
If so:

DoCmd.TransferSpreadsheet _
TransferType:=acExport, _
SpreadsheetType:=acSpreadsheetTypeExcel9, _
TableName:="Table1", _
FileName:="C:\Document\Excel\XLS\Book1.xls", _
HasFieldNames:=True, _
Range:="Sheet3!B10:F40"

Should you need further help, please be more precise .

Ciao
Bruno
 
Thanks! I like this part "CurrentProject.Path" so that the xls file
is going to be in the access folder! Great thing! Thanks!
 
I removed Range:="Sheet3!B10:F40" and put this
Range:="Sheet3" and the code works great! And I also put some more
tables and it works great!
Thanks!
 

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

Back
Top