The Problem (Q-score 10, ranked #19th of 95 in the VBA Core archive)
The scenario as originally posted in 2009
I have two tables in my access database that I want to be able to export to excel.
I can do it by opening the table and then doing File->Export… and then choosing the format and typing in the file name.
However, this way the user actually has to type the name in so there is room for misnaming the file or for saving it as the wrong format or in the wrong location. Also, the two tables have to be exported to two separate workbooks.
What I want to be able to do is make a button on a form that automatically exports one table to one worksheet and the other to another worksheet, both in the same excel workbook.
If putting them in the same workbook isn’t possible, that’s fine. I just want them to automatically be exported to the same directory my access database is saved in.
If you know how to do it, an added perk might be to customize the name to include the date. That way the directory would have historical exports as well. Any advice?
Why this Range / Worksheet targeting trips people up
The question centers on reaching a specific cell, range, or workbook object. In VBA Core, this is the #1 source of failures after activation events: every property (.Value, .Formula, .Address) behaves differently depending on whether the parent Workbook is explicit or implicit.
The Verified Solution — strong answer (top 25 %%) (+26)
5-line VBA Core pattern (copy-ready)
You can use VBA to export an Access database table as a Worksheet in an Excel Workbook.
To obtain the path of the Access database, use the CurrentProject.Path property.
To name the Excel Workbook file with the current date, use the Format(Date, "yyyyMMdd") method.
Finally, to export the table as a Worksheet, use the DoCmd.TransferSpreadsheet method.
Example:
Dim outputFileName As String
outputFileName = CurrentProject.Path & "Export_" & Format(Date, "yyyyMMdd") & ".xls"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "Table1", outputFileName , True
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "Table2", outputFileName , True
This will output both Table1 and Table2 into the same Workbook.
HTH
When to Use It — vintage (14+ years old, pre-2013)
Ranked #19th in its category — specialized fit
This pattern sits in the 79% tail relative to the top answer. Reach for it when your scenario closely matches the question title; otherwise browse the VBA Core archive for a higher-consensus alternative.
What changed between 2009 and 2026
The answer is 17 years old. The VBA Core object model has been stable across Office 2013, 2016, 2019, 2021, 365, and 2024/2026 LTSC, so the pattern still compiles. Changes that might affect you: 64-bit API declarations (use PtrSafe), blocked macros in downloaded files (Mark-of-the-Web), and the shift toward Office Scripts for web-first workflows.