Excel is not actually deleting your macros — it is almost always blocking them or failing to save them because of a security setting, a file format issue, or a Trust Center configuration. The fastest fix is to open File > Options > Trust Center > Trust Center Settings > Macro Settings, confirm macros are enabled (or that the file's location is trusted), and make sure you are saving the workbook as an .xlsm file rather than .xlsx. If the macros vanish after closing and reopening, the file is being saved in a format that cannot store VBA code. Work through the steps below in order; the first two solve the majority of cases.

What You'll Need

  • Microsoft Excel for Windows or Mac (steps below note where they differ; the desktop app is required — Excel for the web cannot run or store VBA macros at all).
  • The workbook containing your macros, ideally with a backup copy before you change any settings.
  • Permission to change Excel options on your computer. On a work or school machine, an IT administrator may have locked these settings.

Step-by-Step

  1. Check the file extension first. In File Explorer (Windows) or Finder (Mac), look at the workbook's name. If it ends in .xlsx, .xls, or .csv, it cannot store macros. Open the file, choose File > Save As, and pick Excel Macro-Enabled Workbook (*.xlsm) from the file type dropdown. This single step fixes the classic "macros disappear after saving" problem, because .xlsx strips VBA code every time you save.
  2. Confirm macros are enabled in the Trust Center. Go to File > Options > Trust Center > Trust Center Settings > Macro Settings. Select Disable all macros with notification (the safest everyday choice) or Enable VBA macros. Avoid Enable all macros unless you fully trust every file you open. Menu labels can differ slightly by Excel version, device, and region, but the Trust Center path is consistent on Windows. On Mac, use Excel > Preferences > Security & Privacy (or the Trust Center equivalent in your version) and look for the macro security setting.
  3. Look for the yellow security bar. When you open a macro-enabled file, Excel may show a message bar under the ribbon saying macros have been disabled, with an Enable Content button. Click it. If you never see the bar, the setting in step 2 is likely set to disable without notification.
  4. Add the file's folder to Trusted Locations. In Trust Center Settings, open Trusted Locations and add the folder where your macro workbooks live. Files in trusted locations open with macros enabled and no prompt. Only trust folders you control — never a shared or downloads folder you do not manage.
  5. Unblock a file downloaded from the internet. Right-click the workbook in File Explorer, choose Properties, and if you see an Unblock checkbox at the bottom of the General tab, tick it and click OK. Windows marks downloaded files as potentially unsafe, and Excel will silently refuse to run their macros until the mark is removed.
  6. Verify the macros still exist in the file. Press Alt+F11 (Windows) or Fn+Option+F11 (Mac) to open the Visual Basic Editor and check that your modules are listed in the Project pane. If they are gone, the code was lost at save time — restore from a backup or your source copy, then re-save as .xlsm.
  7. Save and reopen to test. Close Excel completely, reopen the .xlsm file, enable content if prompted, and run a macro from the Developer tab (Developer > Macros) or your assigned shortcut. If it runs, the problem is solved; if not, move to Troubleshooting.
  8. Repair Office if the problem persists across all files. In Windows, go to Settings > Apps > Installed apps, find Microsoft 365 or Office, choose Modify, and run a Quick Repair, then an Online Repair if needed. This is the last resort because it can take a while and may reset some customisations.

Common Mistakes

  • Saving as .xlsx. This is the number one cause. Excel warns you that macro-free formats cannot store VBA, but people click through the warning. Always use .xlsm for macro workbooks.
  • Confusing "macros disabled" with "macros deleted." A blocked macro still exists in the file; it just will not run. Check the security bar before assuming the code is gone.
  • Enabling all macros globally. This removes the safety net and lets malicious code run from any file. Use trusted locations instead.
  • Trusting a whole drive or network share. Trusted locations should be narrow, specific folders you control.
  • Editing in Excel for the web. The browser version cannot run or preserve VBA. Open macro workbooks in the desktop app only.
  • Ignoring the Protected View bar. Files from email or the internet open in Protected View, where macros cannot run even if enabled. Click Enable Editing first.

Tips

  • Keep a plain-text backup of your VBA code (export modules from the Visual Basic Editor via File > Export File) so a corrupted workbook never costs you the code.
  • Use the Personal Macro Workbook for macros you want available in every workbook; it lives in Excel's startup folder and is already macro-enabled.
  • Name your trusted folders clearly (for example, "Macro Workbooks") so you remember why they are trusted.
  • If you share workbooks with colleagues, tell them the file must be saved as .xlsm and that they will need to enable content on first open.
  • Sign your macros with a digital certificate if your organisation requires it; a trusted signature avoids repeated prompts.

Troubleshooting

Macros run but disappear after reopening. The file is being saved in a non-macro format. Re-save as .xlsm and confirm the title bar no longer shows "[Compatibility Mode]".

No security bar appears and macros never run. Macro Settings is set to disable without notification. Change it to "Disable all macros with notification" so you at least get the prompt.

Settings are greyed out. A work or school policy is controlling Excel. Contact your IT administrator; you cannot override it locally.

Only one file misbehaves. Unblock it in Properties, or move it into a trusted location. If it still fails, the file may be corrupted — open it, copy the sheets into a fresh .xlsm workbook, and re-import the VBA modules.

Macros fail after an Office update. Check Trust Center settings again, since updates can reset some options, and confirm the file is still .xlsm.

Everything fails across all workbooks. Run Office Quick Repair, then Online Repair. Back up your Personal Macro Workbook first.

Frequently Asked Questions

Why does Excel delete my macros when I save?

Because the file is saved as .xlsx or another macro-free format. Excel strips VBA on save. Use Save As and choose Excel Macro-Enabled Workbook (*.xlsm).

Are my macros gone forever?

Usually not. If they are merely blocked, they are still in the file — enable content or trust the location. If they were stripped at save, restore from a backup or re-import your exported code.

Can I use macros in Excel for the web?

No. The browser version cannot run or store VBA macros. Open the workbook in the desktop Excel app.

Is it safe to choose "Enable all macros"?

It is risky. It lets any file run code without warning. Prefer "Disable all macros with notification" plus trusted locations for your own folders.

Why is there no Enable Content button?

Either macro notification is turned off in Trust Center settings, or the file opened in Protected View. Click Enable Editing first, then check Macro Settings.

Do these steps work on Mac?

The concepts are the same, but menu locations differ: look under Excel > Preferences for Security and Trust Center options, and use Finder's Get Info to unblock downloaded files.