Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Excel VBA Not Saving Changes? Fix It Now

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Excel VBA macros often fail to save changes because the workbook isn't explicitly saved after modifications, or because it's opened in read-only mode, protected, or saved as a non-macro-enabled format. The fix is simple: always use Save or SaveAs in your VBA code and ensure the file type supports macros. Below is how to diagnose and resolve this issue for any version of Excel on Windows or macOS.

What You'll Need

  • A Microsoft Excel file (.xlsm, .xlsb, or .xls) that contains VBA code
  • Excel with macros enabled (Macro Settings set to Enable All Macros or Disable All Macros with Notification)
  • Write permissions to the folder where the file is stored
  • Administrative rights if the file is on a network drive or restricted location

Step-by-Step

  1. Open the Excel file that contains your VBA code. If you see a security warning about macros, click Enable Content. If the warning does not appear and macros are disabled, go to File > Options > Trust Center > Trust Center Settings > Macro Settings and select Enable All Macros (for testing only) or Enable All Macros with Notification.
  2. Press Alt + F11 to open the Visual Basic for Applications (VBA) editor. In the Project Explorer, locate your workbook (it will appear as VBAProject (YourFileName.xlsm)).
  3. Find the module or ThisWorkbook object where your macro runs. After any code that modifies cells, sheets, or properties, add the line: ActiveWorkbook.Save or ThisWorkbook.Save. Do not rely on Excel’s auto-save — always force a save in VBA after changes.
  4. If you are saving to a different location or filename, use ThisWorkbook.SaveAs Filename:="C:\Path\To\YourFile.xlsm", FileFormat:=52. The FileFormat number 52 is for .xlsm (macro-enabled). Never use 51 (.xlsx) — it strips macros and prevents saving changes to VBA code.
  5. Test your macro by running it manually from the VBA editor (F5) or from Excel (Alt + F8). After execution, manually check the file’s Modified date in File Explorer. If it hasn’t updated, the save command failed.
  6. Close Excel completely, then reopen the file. Check if your changes are still there. If not, the save command was never executed or the file was opened as read-only.
  7. If the file is on a network drive, copy it to your local desktop first, test the macro, then save and copy it back. Network permissions often block save operations silently.
  8. Use Application.DisplayAlerts = False before Save or SaveAs to prevent pop-ups from halting execution, then restore with Application.DisplayAlerts = True afterward.

Common Mistakes

  • Using Save instead of SaveAs when the file was opened from a read-only location or network drive — this causes Excel to silently ignore the save request.
  • Saving as .xlsx (FileFormat:=51) after modifying VBA code — macros are permanently deleted and changes to code are lost.
  • Forgetting to use ThisWorkbook or ActiveWorkbook — if your macro opens or activates another workbook, Save may target the wrong file.
  • Running macros from a template (.xltm) instead of a workbook (.xlsm) — templates are not meant to be saved after editing.
  • Having the file open in another instance of Excel, or locked by another user on a shared drive — Excel prevents saving and gives no warning in VBA.
  • Assuming Excel saves automatically — VBA does not trigger Excel’s auto-save. You must code the save explicitly.

Tips

  • Always use ThisWorkbook.Save in your macros unless you specifically need to save a different workbook.
  • Before saving, check if the workbook is read-only with If ThisWorkbook.ReadOnly Then MsgBox "Workbook is read-only" End If — this helps catch permission issues early.
  • Use Application.EnableEvents = False before Save to prevent event-triggered macros from interfering, then set it back to True after.
  • Log your save actions: add Debug.Print "Saved at " & Now() to the VBA code. Open the Immediate Window (Ctrl + G) to see timestamps and confirm execution.
  • Test your macro on a copy of the file first. Never test save changes on a critical production file until you’re certain it works.
  • If saving fails, try saving manually in Excel (Ctrl + S) right after running the macro. If manual save works, your VBA code has a logic error — not a system issue.

Troubleshooting

  1. If changes disappear after closing Excel, check the file extension. If it ends in .xlsx, your file lost its macros. Reopen the original .xlsm file and reapply the fix.
  2. If you get a "Run-time error '1004': SaveAs method of Workbook class failed", the path is invalid or you lack write permissions. Try saving to your desktop with a simple name like "Test.xlsm".
  3. If Excel freezes during the save, disable add-ins. Go to File > Options > Add-ins, select COM Add-ins, click Go, then uncheck all. Restart Excel and test again.
  4. Check if the file is open elsewhere: open Task Manager (Ctrl + Shift + Esc), go to the Details tab, look for multiple Excel.exe processes. End all but one, then try again.
  5. Scan the file for corruption. Open Excel, go to File > Open > Browse, select your file, click the arrow next to Open, and choose "Open and Repair".
  6. On macOS, file paths use forward slashes (/) instead of backslashes (\). Use "/Users/YourName/Desktop/Test.xlsm" for SaveAs.
  7. If nothing works, create a new .xlsm file, copy all sheets and code modules over manually, then test the macro again. Sometimes the original file’s structure is corrupted.

Frequently Asked Questions

Why does my VBA macro run but not save changes?

Your code likely lacks a Save or SaveAs statement. Excel does not auto-save changes made by VBA. Always include ThisWorkbook.Save after modifications.

Can I save a VBA-enabled file as .xlsx?

No. Saving as .xlsx removes all VBA code permanently. Use .xlsm (FileFormat:=52) to preserve macros. If you save as .xlsx, your code is gone and cannot be recovered.

Why does Excel ask me to save when I close even after running Save in VBA?

This happens if your macro modifies the workbook but doesn’t save it properly, or if changes were made after the Save command ran. Add a final Save just before the macro ends.

Does Excel’s AutoRecover save VBA changes?

No. AutoRecover only saves the state of cell data, not VBA code. If Excel crashes, your macro code may be lost unless you manually saved the file.

Can network drives cause VBA save failures?

Yes. Network drives often have permissions or latency issues that prevent SaveAs from working. Always test locally first. Use ActiveWorkbook.SaveCopyAs to create a backup on the network if direct save fails.

What’s the difference between Save and SaveAs in VBA?

Save rewrites the current file using its existing name and location. SaveAs lets you change the name, location, or file format. Use Save when you want to overwrite the current file. Use SaveAs to create a copy or change format — but always use FileFormat:=52 for macros.