If your VBA code, Developer tab, or macros stop working in Excel, the fix is almost always one of a short set of causes: the workbook lost its macro-enabled format or was saved as .xlsx, macro security blocks execution, Trust Center settings or the Mark-of-the-Web on a downloaded file put it in Protected View, a missing reference in the VBA project breaks compilation, or an Add-in and the Bitness mismatch between Office versions interferes. Work through the checks below from simplest to most invasive, and in most cases macros will run again without reinstalling anything. The exact labels in Excel's dialog boxes can differ slightly by version, device and region, so the wording on your screen may vary a little from what follows.

What You'll Need

  • A Windows or Mac copy of Microsoft Excel desktop with the VBA editor available (Microsoft 365 or a recent perpetual version). VBA is not available in Excel for the web.
  • Access to the Developer tab, or the ability to enable it (it is hidden by default).
  • Administrator-level rights if you need to change Trust Center settings from the system policy.
  • The original macro-enabled file (.xlsm, .xlsb or .xls), not a copy that is missing its code.
  • For Mac users, macro settings are in the Excel preferences under Security, and can be locked by your organisation.

Step-by-Step

  1. Check the file format. Open File > Save As and look at the top of the Save As dialog. If the file was saved as Excel Workbook (*.xlsx), all macros are stripped on save. Choose the macro-enabled formats instead: .xlsm (standard macro workbook), .xlsb (binary, faster for large projects) or .xls (legacy). Re-save, then close and reopen. This one mistake accounts for a huge share of "my macro disappeared" reports.
  2. Enable the Developer tab and look at the VBA project. If the Developer tab is missing, right-click the ribbon and choose Customize the Ribbon, then tick Developer in the right-hand list. Open the Visual Basic editor (Alt+F11), then View > Project Explorer and expand the workbook's folder. Confirm the module still exists and contains code. If the module is empty, the code was lost when the file was saved as .xlsx.
  3. Turn on macros for the session. When you open an .xlsm file, Excel shows a yellow security bar reading "Macros have been disabled" (or similar). Click Enable Content. If the file came from the internet or email, Excel may also show Protected View at the top; click Enable Editing first, then Enable Content.
  4. Unblock the downloaded file. Right-click the .xlsm file in File Explorer, choose Properties, and look for an Unblock option (or an Unblock checkbox under the Security heading). Tick it, apply, and reopen. On macOS this protection behaves differently and may need you to allow the file in System Settings > Privacy & Security.
  5. Adjust Trust Center macro settings. Go to File > Options > Trust Center > Trust Center Settings > Macro Settings. Choose "Disable all macros with notification" if you want the Enable Content prompt, or "Enable all macros" only for code you fully trust. Add your working folder under Trusted Locations so files there bypass the prompts. On Mac, use Excel > Preferences > Security.
  6. Watch for the Bitness mismatch. Office runs in 32-bit or 64-bit. VBA code that calls Windows APIs with Declare statements often fails with a compile error on the other bitness, typically an error about a long pointer or PtrSafe. Add the PtrSafe and LongPtr keywords to declarations so the code works in both, or install matching Office builds on the machines that need to run the shared file.
  7. Fix broken references. In the Visual Basic editor, open Tools > References. Any item shown with "MISSING:" in front of it will break compilation. Uncheck it, then set a reference to the correct version of that library. Close and restart Excel afterwards. This is common when a workbook moves between computers with different Office builds.
  8. Check for compile errors and Debug mode. In the editor, choose Debug > Compile VBAProject. Fix any highlighted line before running. Press F5 only after the compile succeeds; the code stopping mid-run often means the editor is in break mode from a prior error.
  9. Test with a minimal macro. Add a new module (Insert > Module) and run a single line in the Immediate window (Ctrl+G), such asMsgBox "ok". If that works, the problem is in your specific code or references, not in Excel's macro system.
  10. Repair Office. If macros are blocked across every file, use Settings > Apps > Installed apps, select Microsoft 365, choose Modify, then Quick Repair, and try Online Repair if Quick Repair does not help. Manage your add-ins first (File > Options > Add-ins) and disable any COM Add-in that could interfere.

Common Mistakes

  • Saving as .xlsx out of habit, which silently deletes all VBA code every time.
  • Clicking Enable Content once and assuming it applies to every file; it only applies to that file in that session unless the folder is a Trusted Location.
  • Leaving Protected View on and wondering why macros do not respond; nothing runs until you enable editing.
  • Editing one copy of a shared workbook while other users hold an older version, so the code and the version numbers do not match.
  • Upgrading Office and reusing API declarations without PtrSafe, causing compile errors only on some machines.
  • Assuming Excel for the web can run VBA scripts; it cannot.

Tips

  • Keep a pristine .xlsm template and save a fresh copy for each project.
  • Store your reusable code in the Personal.xlsb workbook if you want the same macros available in every Excel window on that machine.
  • Document which Office build and bitness each file is written for, since that is the most common source of compile failures.
  • If you share files, prefer avoiding Windows API calls unless you ship both 32- and 64-bit compatible declarations.
  • Back up the workbook before changing reference settings or repairing Office.

Troubleshooting

If the Enable Content button is greyed out, the file is in Protected View; click Enable Editing first. If the button is gone entirely, check the Trust Center macro settings and clear any policy applied by your organisation, which may override your own choices and cannot be changed from the user account.

If a macro runs but throws a runtime error, note the error number and the highlighted line, then check that the referenced sheets, ranges and workbook names still exist. Renamed sheets are a frequent cause of "subscript out of range" errors.

If the code compiles on one computer but not another, compare Office bitness and referenced libraries first, then Windows and Excel versions. If a workbook downloaded from a colleague never prompts to enable macros, verify it was saved with the macro-enabled extension, since the original code may already be missing.

If Quick Repair fails and errors persist across all workbooks, an Office reinstall may be needed. Removing and reinstalling the desktop app does not delete your saved files, but any local customisations and add-ins must be reconfigured. Note that installing a new Office build can also reset the Trust Center to defaults.

Frequently Asked Questions

Why does my macro vanish after I save it?

The workbook was almost certainly saved as an .xlsx. That format cannot hold VBA code, so Excel discards it. Save as .xlsm instead and your code will persist.

Does VBA work in Excel for the web?

No. The browser version cannot run VBA macros. You need the desktop Excel app to edit and run them; macros will still run in desktop Excel for Mac, though with some differences.

What does "Macros are disabled" with no Enable Content button mean?

Usually the file is in Protected View or your macro settings are set to disable all with no notification. Enable editing first, then review Trust Center > Macro Settings.

Why do I get a compile error for PtrSafe?

That happens when 32-bit and 64-bit Office interact with API declarations. Add PtrSafe and LongPtr so the same code compiles under both bitnesses.

Can I run VBA macros from a file on a network share?

Yes, if the share is added under Trusted Locations, but files from untrusted locations may still prompt or be blocked. Add the share explicitly rather than disabling all protection.

Does repairing Office remove my macros?

No, Quick Repair and Online Repair do not delete the content of your workbooks. Back up files first anyway, since repairs can reset customisations and add-ins.