Fix Excel VBA SaveAs Error 1004 When Saving an Invoice
Question details
Resolve an intermittent error when an Excel macro saves a copied invoice sheet as a new workbook.

- Product
- Microsoft Excel VBA
- Device & OS
- not provided
- Scenario
- A macro combines a base number and the value in cell I2 to name an invoice workbook, then calls Workbook.SaveAs.
- Observed behavior
- SaveAs intermittently returns error 1004 or a document-not-saved message, including after the workbook is reopened.
Open the source workbook and locate the macro’s SaveAs line in the VBA editor. Check the current value of cell I2 and identify the destination folder and file extension used by the macro.
Validate the generated invoice filename and path
Use this first when the filename is assembled from a base number and cell I2.
Press Alt+F11 to open the VBA editor, find the SaveAs line, and inspect the variables used to build its filename and full path. Use Debug.Print with the path expression and view the result in the Immediate window, opened with Ctrl+G.
Compare the printed filename with the value in cell I2 and the base number. On Windows, remove or replace invalid filename characters such as \ / : * ? " < > and |; also check for unintended spaces or separators.
Open the printed destination folder in your file manager and confirm that it exists and is accessible. In the macro, make sure the folder path and filename are joined with the appropriate path separator.
Return to Excel, run the macro from the Macros dialog, and check whether the new invoice file appears in the destination folder.

Check file conflicts, permissions, and the SaveAs format
Use these checks if the generated path looks valid but SaveAs still fails.
Work with invoice spreadsheets in WPS Office
WPS Office is a free, lightweight alternative with a familiar spreadsheet interface and Microsoft Office format compatibility, making it easy to move everyday invoice work between office suites. It does not fix Excel’s VBA SaveAs error, and macro support may vary.

Frequently Asked Questions
Why can cell I2 cause a SaveAs error?
The macro uses I2 to build the invoice filename. On Windows, characters such as slashes, colons, and question marks are not allowed in filenames. Inspect the complete path in the VBA editor’s Immediate window.
What if the filename looks correct but the macro still fails?
Check that the destination folder exists, you can write to it, and a file with the same name is not open. You can also test the folder through Excel’s File > Save As.
Should the new invoice workbook be XLSX or XLSM?
Use .xlsx with xlOpenXMLWorkbook if the saved workbook does not need VBA. Use .xlsm with xlOpenXMLWorkbookMacroEnabled if it must retain VBA code, including code attached to a copied sheet.
Can WPS Office fix the Excel VBA error?
No. The error occurs in Microsoft Excel’s SaveAs operation, so check the macro and its destination in Excel. WPS Office is an alternative for working with spreadsheets, but macro support may vary.




