Export Access Table to Excel Temple using macro

griffibr

New Member
Joined
Oct 7, 2008
Messages
10
How would I generate a macro to export an access table or query to an existing excel template.

And, suppose I want to export two table to the same excel file, just different tabs. Can this be done using the macro option in access?

Thank you,

Bryant
 
Sounds like an invalid path all right.

What's the actual, full correct path to your file?


Code:
Sub GetMyPath()
'Run in Excel workbook in a folder of your choice.
'Be sure the file has been saved at least once.
     MsgBox ActiveWorkbook.FullName
End Sub

It might be something like:
C:\Documents and Settings\username\My Documents\Test.xls

Do yourself a favor, test the code out like this:
Code:
Public Sub ExportTblToExcel()
   strFullPath = "C:\TestExportToExcel.xls"
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7, "tblCars", strFullPath, False
    MsgBox ("Export Complete")
End Sub

At least see if it works!

Also try:
Code:
Public Sub ExportTblToExcel()
   strFullPath = "C:\TestExportToExcel.xls"
    DoCmd.TransferSpreadsheet acExport, , "tblCars", strFullPath, False
    MsgBox ("Export Complete")
End Sub
Leaving the 2nd argument at its default value, which would be acSpreadSheetTypeExcel8 (or 9).

Edit: If you have a table called tblCars, you should now have a file called TestExportToExcel.xls on your C: drive. But please don't delete any other files on the C: drive - windows keeps some crucial files there. As a rule, I don't save things there and normally I'd create at least a temp folder for such a file. We need to get a successful routine here though! :)
 
Last edited:
Upvote 0

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Hi,

I'm an accountant by trade, not a programmer, so I didn't quite understand the whole thread. But I have a similar problem. I managed to create the following VB code that extracts my multiple tables to one Excel File:
Public Sub ExportTblToExcel()
strFullPath = "C:\Documents and Settings\dupuism3\Desktop\Details.xls"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7, "A561_All", strFullPath, False
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7, "A561_DG", strFullPath, False
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7, "A561_NCASS", strFullPath, False
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7, "A561_OSS", strFullPath, False
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7, "A561_PTPS", strFullPath, False
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7, "A561_RPT 1", strFullPath, False
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7, "A561_RPT 2", strFullPath, False
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7, "A561_RPT 3", strFullPath, False
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7, "A561_RPT 4", strFullPath, False
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7, "A561_TAS", strFullPath, False
End Sub


However, I can't seem to be able to run it from the Access Macro using the "Runcode" command. I've done some research, and read that the "Runcode" command will only run Function procedures and that I have to write my Sub procedure as a Function procedure - except that none of the literature I've seen tells me how to do this.

Thank you.
 
Upvote 0
nevermind, i figured it out.

is there a way to format the table in excel using the macro i created in access? i need to create a subtotal for any changes in a specific field (like the "subtotal" option in excel) but i'd prefer to do it at the same time as the export.
 
Upvote 0
Hi,

I would like to know if its possible to customized the Filename of exported Excel. for example i want to have a monthly filename. 01 Jan (Filename), 02 Feb (Filename), etc....
 
Upvote 0
Hi,

I am in need to export a particular table say "AAA" from multiple access databases with file names "BBB (1), BBB (2)".....etc., into an excel worksheet with tall the tables appended.

It would be nice if someone can help me.

Regards
 
Upvote 0

Forum statistics

Threads
1,216,741
Messages
6,132,450
Members
449,729
Latest member
davelevnt

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top