Search code examples
vbaexcelms-access-2013excel-2013

Access VBA To Save Table As Spreadsheet


I am using this syntax to export a table to a .xlsx file. The issue that I Have is that anytime I try to open the file, this error is thrown:

Excel cannot open the file because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file.

I am using Excel 2013 and Access 2013 - and this is the export line I use

DoCmd.TransferSpreadsheet transfertype:=acExport, spreadsheettype:=acSpreadsheetTypeExcel12, TableName:=strTable, filename:=strWorksheetPath, hasfieldnames:=True

What is the way to export an access table to excel so you can open the file error free?


Solution

  • Try:

    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, strTable, strWorksheetPath, True