Exporting to excel

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
 
T

Tom Wickerath

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
 
B

Bruno Campanini

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
 
D

danijela.simunovic

Thanks! I like this part "CurrentProject.Path" so that the xls file
is going to be in the access folder! Great thing! Thanks!
 
D

danijela.simunovic

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!
 
Top