Fix Excel VBA SaveAs Errors for Macro-Enabled Workbooks
Question details
Save a workbook containing a VBA project without losing its macros or triggering a format-related SaveAs error.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A VBA macro saves a workbook created from a macro-enabled source file.
- Observed behavior
- Excel may attempt to save the workbook as XLSX, which cannot store VBA macros, and the SaveAs operation may produce a warning or run-time error 1004.
Identify the workbook your macro should save and prepare a valid destination folder and file name ending in .xlsm. Open the VBA editor and locate the SaveAs statement that saves the workbook.
Specify the macro-enabled workbook format in VBA SaveAs
Use this solution when a workbook contains VBA macros and must retain them after saving.
In Excel, press Alt+F11 to open the Visual Basic Editor, then open the module containing the SaveAs statement.
Assign a complete destination path ending in .xlsm to a variable, for example: FName = "C:\Reports\MyWorkbook.xlsm". Use a folder that exists and that you can write to.
Replace the existing SaveAs statement with: ActiveWorkbook.SaveAs Filename:=FName, FileFormat:=xlOpenXMLWorkbookMacroEnabled. Ensure ActiveWorkbook refers to the workbook you intend to save.
Run the macro from the VBA editor or Excel, then open the saved .xlsm file and check that the expected VBA project is present.

Work with Excel Files in WPS Office
WPS Office is a free, lightweight Office alternative with a familiar spreadsheet interface and support for common Excel formats, making it easy to move everyday workbook tasks. It does not fix Microsoft Excel VBA errors; verify macro support for your WPS version before relying on VBA workflows.

Frequently Asked Questions
Why does Excel warn me when VBA saves a workbook as XLSX?
The XLSX format cannot store VBA macros. To retain them, use SaveAs with FileFormat:=xlOpenXMLWorkbookMacroEnabled and a file name ending in .xlsm.
What does Excel VBA run-time error 1004 mean during SaveAs?
Error 1004 can have several causes. Check the SaveAs FileFormat, the file extension, the complete destination path, and whether you have permission to write to the folder.
Is changing the file extension to .xlsm enough?
Specify both an .xlsm file name and FileFormat:=xlOpenXMLWorkbookMacroEnabled in the SaveAs statement so the file extension and workbook format match.
Can I save the workbook as XLSX if I do not need the macros?
Yes. Save as XLSX only if you intentionally want a macro-free workbook, and review Excel's warning before confirming the save.




