VBA & Macro Problems

Fix Excel VBA SaveAs Errors for Macro-Enabled Workbooks

Jason MillerJason Miller Nov 25, 2026 869 views

Question details

Save a workbook containing a VBA project without losing its macros or triggering a format-related SaveAs error.

Fix Excel VBA SaveAs Errors for Macro-Enabled Workbooks
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.
Before you start

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.

Solution 1Recommended

Specify the macro-enabled workbook format in VBA SaveAs

Use this solution when a workbook contains VBA macros and must retain them after saving.

1
Open the VBA procedure

In Excel, press Alt+F11 to open the Visual Basic Editor, then open the module containing the SaveAs statement.

2
Set the destination file name

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.

3
Specify the XLSM format

Replace the existing SaveAs statement with: ActiveWorkbook.SaveAs Filename:=FName, FileFormat:=xlOpenXMLWorkbookMacroEnabled. Ensure ActiveWorkbook refers to the workbook you intend to save.

4
Run and verify

Run the macro from the VBA editor or Excel, then open the saved .xlsm file and check that the expected VBA project is present.

Specify the macro-enabled workbook format in VBA SaveAs
Keep the file format and extension consistent: XLSX cannot store VBA macros. Do not suppress the format warning to save as XLSX unless you intentionally want to remove the macros. Use a variable such as FName instead of Name to avoid conflicts with VBA members.
Free Microsoft Office alternative

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.

Open and edit common Microsoft Excel formats, including XLSX and XLSMUse familiar spreadsheet tools for everyday workbook tasksMove existing Office files into a lightweight, easy-to-use workspaceReview macro-enabled workbooks while checking VBA support for your version
microsoft office alternative - wps office

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.