Fix Excel Cannot Save This Workbook Error After Running Macros
Question details
The user encounters an error warning that a workbook cannot be saved after running or adding a macro, and needs to know how to save the file without losing the VBA code.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Saving an Excel file after recording or writing a VBA macro.
- Observed behavior
- Excel displays a warning that the workbook cannot be saved in a macro-free format, prompting the user to either save without macros or choose a different format.
Before attempting to save again, ensure you do not accidentally click 'Yes' on the warning prompt, as this will permanently remove your macro code from the workbook.
Save the File as an Excel Macro-Enabled Workbook (.xlsm)
To preserve your VBA macro code, change the file format from a standard workbook (.xlsx) to a macro-enabled format (.xlsm).
Standard Excel workbooks (.xlsx) are not designed to store VBA macros for security reasons. When you attempt to save a workbook containing macros in this format, Excel warns you to prevent accidental data loss. Saving as a Macro-Enabled Workbook resolves this problem completely.
When the warning message appears asking if you want to save as a macro-free workbook, click **No** to cancel the process and keep your macros active.
Click on the **File** tab in the top-left corner of Excel and select **Save As** from the left sidebar.
Choose **Browse** or select your desired save location on your local computer or cloud drive.
In the **Save as type** dropdown menu below the file name, select **Excel Macro-Enabled Workbook (*.xlsm)**.
Click **Save**. Your workbook and all associated VBA macro codes are now securely saved.

Save and Run Macros Seamlessly in WPS Office
WPS Spreadsheet provides excellent compatibility with Excel macros and VBA code. You can easily create, edit, and save macro-enabled workbooks (.xlsm) securely without losing any of your automated scripts.
- 1. Open File in WPS Spreadsheet: Open your macro-integrated document using WPS Spreadsheet.
- 2. Access Save Menu: Click on **Menu** in the top left corner and select **Save As**.
- 3. Open Format Options: In the save dialog box, click on the file format dropdown menu to view supported extensions.
- 4. Select Macro Format: Select **Microsoft Excel Macro-Enabled Workbook (*.xlsm)** from the list of available formats.
- 5. Save the Document: Choose your preferred save location and click **Save** to securely store your workbook and VBA codes.

Frequently Asked Questions
Why does Excel show a warning when saving a file with macros?
Standard Excel workbooks (.xlsx) are not structured to store macro code. This is a built-in security measure by Microsoft to differentiate standard files from files containing executable code. Excel warns you to prevent the accidental loss of your VBA scripts during the save process.
What happens if I accidentally clicked "Yes" on the macro warning prompt?
Clicking "Yes" instructs Excel to proceed with saving the file as a standard macro-free workbook. Doing this permanently strips and deletes any VBA macros contained in that session. Unless you have a previous backup or an earlier saved version, the macro code cannot be recovered.
Can I set Excel to always save as a macro-enabled workbook?
Yes. You can change your default save format by going to File > Options > Save. Under the "Save workbooks" section, open the "Save files in this format" dropdown menu and select "Excel Macro-Enabled Workbook (*.xlsm)". Click OK to apply the changes.




