Originally Posted by
SteveF
Agree with Ajetrumpet -- You need a database object to export, not code within a VBA module.
However, that object doesn't need to be a table: a query will do just as well. A query in the Queries collection is actually SQL underneath, and if needed, you can use VBA to modify the SQL of a query prior to export:
Dim qdf As DAO.QueryDef, dbs As DAO.Database
Set dbs = CurrentDb
Set qdf = dbs.QueryDefs("ExportQuery")
qdf.SQL = "SELECT * FROM WorkTable;"
qdf.Close
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "ExportQuery", "ExcelFileName", True
Replace the items above with the actual SQL string you want to use (qdf.SQL), the name of the query and the full path to the Excel file.
Steve