VBA & Macro Problems

Fix Excel VBA SaveAs Error 1004 When Saving an Invoice

Algirdas JasaitisAlgirdas Jasaitis Nov 25, 2026 869 views

Question details

Resolve an intermittent error when an Excel macro saves a copied invoice sheet as a new workbook.

Fix Excel VBA SaveAs Error 1004 When Saving an Invoice
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.
Before you start

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.

Solution 1Recommended

Validate the generated invoice filename and path

Use this first when the filename is assembled from a base number and cell I2.

1
Inspect the generated path

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.

2
Check the filename

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.

3
Check the destination folder

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.

4
Run the macro again

Return to Excel, run the macro from the Macros dialog, and check whether the new invoice file appears in the destination folder.

Validate the generated invoice filename and path
Check the complete filename: Even if a slash is not intended as part of the filename, inspect the final path produced by the macro to see exactly how the base number and I2 value are combined.
Free Microsoft Office alternative

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.

Open and edit invoice spreadsheets in WPS SpreadsheetsCompatible with Microsoft Excel formats including XLSX and XLSFree, lightweight office suite with a familiar interfaceMove everyday spreadsheet files between office suites
microsoft office alternative - wps office

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.