Fix Microsoft Excel Macro Changes Not Saving and VBA Editor Closing
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.

- 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.
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.
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.
In Excel, select File > Save As > Browse to choose a save location and file format.
Open the Save as type list, select Excel Macro-Enabled Workbook (*.xlsm), and select Save.
If Excel warns that the selected format may not support features, select Use Excel Macro-Enabled Workbook or Yes to keep the VBA project.
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.

Enable macros and test the VBA project in a new workbook
Use this when the file opens but macros are blocked, unavailable, or behave differently after reopening.
Start Excel in Safe Mode and isolate add-ins or installation issues
Use this when Excel or the VBA Editor closes, freezes, or crashes while you edit macro code.
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.

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.




