VBA & Macro Problems

Fix Microsoft Excel Macro Changes Not Saving and VBA Editor Closing

Natalie TaylorNatalie Taylor Nov 12, 2026 869 views

Question details

The user needs to save recorded macro or VBA code changes in Microsoft Excel and prevent Excel or the VBA Editor from closing unexpectedly during editing.

Fix Microsoft Excel Macro Changes Not Saving and VBA Editor Closing
Product
Microsoft Excel VBA and recorded macros
Device & OS
not provided
Scenario
The user is recording or editing a macro and wants the workbook to retain VBA changes after saving.
Observed behavior
Macro changes are not retained, or Excel closes while the user is editing code in the Visual Basic for Applications Editor.
Before you start

Check the workbook's current file type in Excel and note any error message shown when the VBA Editor closes. If the file is stored in OneDrive, SharePoint, or another synced location, confirm that it is fully available locally before testing.

Solution 1Recommended

Save the workbook as an Excel Macro-Enabled Workbook (.xlsm)

Use this first when recorded macros or VBA code disappear after you save and reopen the workbook.

Standard Excel Workbook (.xlsx) files cannot store VBA projects. Save the file in a macro-enabled format before closing Excel.

1
Open the Save As window

In Excel, select File > Save As > Browse to choose a save location and file format.

2
Choose the macro-enabled format

Open the Save as type list, select Excel Macro-Enabled Workbook (*.xlsm), and select Save.

3
Confirm the format warning

If Excel warns that the selected format may not support features, select Use Excel Macro-Enabled Workbook or Yes to keep the VBA project.

4
Verify the saved code

Press Alt+F11 to open the Visual Basic Editor, confirm that the code is still listed under the workbook project, then save again with Ctrl+S.

Save the workbook as an Excel Macro-Enabled Workbook (.xlsm)
Macro code can be preserved: An .xlsm workbook retains VBA modules and recorded macros, while an .xlsx workbook removes them when saved.
Free Microsoft Office alternative

Use WPS Office for Macro-Enabled Excel Workbooks

If Microsoft Excel continues to close while you edit or save workbook content, WPS Office provides a free, lightweight alternative with a familiar spreadsheet interface and smooth migration for common Excel files. You can open, review, and manage compatible workbook content without changing your usual document workflow.

Free and lightweight spreadsheet software for everyday workbook editingOpens and saves Microsoft Excel .xlsx and .xls files with strong format compatibilitySupports working with macro-enabled Excel .xlsm workbooks for compatible document workflowsFamiliar ribbon-style interface helps make the move from Microsoft Excel easierConvenient access to local and cloud-stored spreadsheet files
microsoft office alternative - wps office

Frequently Asked Questions

Why did my recorded macro disappear after I saved the Excel workbook?

The workbook was likely saved as an .xlsx file, which cannot retain VBA. Use File > Save As and select Excel Macro-Enabled Workbook (*.xlsm), then save the workbook again.

How do I open the VBA Editor in Microsoft Excel?

Open the workbook in Excel and press Alt+F11. You can also enable the Developer tab through File > Options > Customize Ribbon, then select Developer > Visual Basic.

Can macro security settings delete my VBA code?

No. Macro security settings usually prevent code from running; they do not delete code. Missing code is more commonly caused by saving in .xlsx format, editing the wrong workbook project, or file corruption.

What should I do if Excel closes when I open or edit VBA code?

Run Excel in Safe Mode by pressing Windows+R and entering excel /safe. If it works there, disable add-ins through File > Options > Add-ins and test again. Then update or repair Office if needed.

What information is useful when reporting an Excel VBA crash?

Provide your Excel version, operating system, exact error message, workbook storage location such as OneDrive or SharePoint, and a sanitized sample workbook that reproduces the issue.