Export MS Access tables through VBA to an excel spreadsheet in same directory -
I have two tables in my access database that I want to be able to export to Excel
I am opening the table and then exporting File-> ... and then selecting the file name I can select the format.
However, in this way the user has to actually type the name, so there is room to give the wrong name to the file or to incorrect format or to save as a wrong place. Also, two tables are to be exported into two separate workbooks
What I want to be able to do is make a button on a form that automatically gets a table In a worksheet and in another worksheet , both of which are the same Excel workbook
if it is not possible to put them in the same workbook, is. I want them to be automatically exported in the same directory so that my access database can be saved.
If you know how to do this, then an extra money might possibly be to customize the name to include the date. In this way, there will be historical exports in the directory. Any advice?
You can use VBA to export an Access database table as a worksheet in an Excel workbook for. To obtain the path of the database, use To make the file name with the Excel workbook today's date, use Finally, to export the table as a worksheet, use the Example: This will production Table1 and table 2 in the same workbook. HH CurrentProject.Path
property. format (date, "YYYYMMDD")
method. DoCmd.TransferSpreadsheet
method.
dim Autputfailnam string output as Menfailnam = CurrentProject.Path and amp; "\ Export_" & amp; Format (Date, "Yyaymmad") & amp; ".xls" DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "Table1", outputFileName, True DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "Table 2", outputFileName, True