Excel VBA Cannot Run the Macro? Fixes That Work

VBA & macros · Updated November 22, 2026

If Excel says it cannot run the macro, the cause is almost always a security setting, a disabled workbook, or a code error—not a broken installation. The fix usually takes under a minute: enable macros in the Trust Center, unblock the file, or check the VBA editor for a syntax issue. Below are the exact steps for each cause, plus how to prevent the problem from returning.

Why Excel Blocks Macros by Default

Since 2007, Excel has shipped with macro security set to Disable all macros with notification. This means when you open a workbook containing VBA code, Excel silently disables the macros and shows a yellow security bar under the ribbon. If you click Enable Content, the macros run; if you ignore it, they don’t. Many users never notice the bar and later see the message “Cannot run the macro” when they try to trigger a macro via a button or shortcut.

Beyond that default, Excel also blocks macros from files downloaded from the internet. Windows marks such files with a Mark of the Web (MOTW) flag. Even if you enable content once, the flag can cause Excel to re-block the file each time it is opened from a downloaded location.

The Most Common Causes (and How to Fix Each)

Here is a checklist of the usual culprits, ordered from most to least frequent:

  • Macros disabled in Trust Center – Go to File > Options > Trust Center > Trust Center Settings > Macro Settings. Select Enable all macros (temporarily) or better, add the folder to Trusted Locations.
  • File is blocked because it was downloaded – In Windows File Explorer, right-click the file, choose Properties, and check Unblock if the box appears. Then reopen.
  • Workbook is saved as .xlsx – Macros are not stored in .xlsx files. Re-save as .xlsm (macro-enabled workbook) using File > Save As.
  • VBA project is password-protected or corrupted – If you see “Cannot run the macro” when you press F5 in the editor, the code may have a compile error or a missing reference.
  • Macro is in a different workbook – If the macro is in Personal.xlsb or another add-in, it must be installed and referenced correctly.

How to Enable Macros Safely (Step-by-Step)

For a single file, the safest method is to unblock it and then enable content:

  1. Close Excel completely.
  2. In Windows File Explorer, right-click the workbook and select Properties.
  3. On the General tab, check Unblock if it is present, then click OK.
  4. Open the workbook in Excel. If the yellow bar appears, click Enable Content.
  5. If the bar does not appear, go to File > Options > Trust Center > Trust Center Settings > Macro Settings and choose Disable all macros with notification (the default) – then reopen the file.

For a folder you trust (like your own project folder), add it to Trusted Locations so every file there runs macros without prompting. Go to File > Options &em; Trust Center > Trust Center Settings > Trusted Locations, click Add new location, browse to the folder, and check Subfolders of this location are also trusted.

When the Error Is Actually a Code Problem

Sometimes “Cannot run the macro” appears because the VBA code itself has an error. Common triggers:

  • Compile error – Press Alt+F11 to open the VBA editor, then go to Debug > Compile VBAProject. If a line is highlighted in yellow, fix the syntax (e.g., missing End If or a typo in a variable name).
  • Missing reference – In the VBA editor, go to Tools > References. If any item says “MISSING:”, uncheck it and find the correct library or reinstall the add-in that provides it.
  • Macro name mismatch – The button or shape may call a macro name that doesn’t exist. Check the Assign Macro dialog (right-click the button > Assign Macro) and ensure the name matches exactly.
  • Protected worksheet – If the macro tries to change a cell on a protected sheet, it will fail with a runtime error (often 1004). Unprotect the sheet temporarily or add Worksheet.Unprotect at the start of the macro.

To test if the code runs at all, press F5 in the VBA editor with the cursor inside the macro. If it runs there but not from a button, the button assignment is the issue.

How to Check if a Macro Is Disabled in the VBA Editor

If you open the VBA editor (Alt+F11) and see a message like “Macros are disabled” or the project tree is grayed out, Excel has blocked the project. This happens when the file is from the internet or when a group policy disables VBA. To fix:

  • Unblock the file as described above.
  • If you are on a work computer, your IT department may have set Disable VBA via Group Policy. You cannot override that; contact your administrator.
  • Check if the file is in a Protected View – click File > Info and look for a red banner. Click Enable Editing first.

Comparing Macro Security Options in Excel

Excel offers four macro security levels in the Trust Center:

  • Disable all macros without notification – Macros never run, and you don’t get a prompt. Good for high-security environments, but you’ll see the “Cannot run” error if you try to run a macro.
  • Disable all macros with notification – Default. Macros are disabled, but you see a yellow bar to enable them.
  • Disable all macros except digitally signed macros – Only macros with a valid digital signature run. Unsigned macros are blocked.
  • Enable all macros – Runs everything. Not recommended for untrusted files, but it’s the quickest way to test.

For a workaround, you can also use VBA Project Protection – but that only locks the code, not the execution.

Preventing “Cannot Run the Macro” in the Future

Once you fix the immediate issue, adopt these habits:

  • Always save macro workbooks as .xlsm, not .xlsx.
  • Keep your own macro files in a trusted folder (add it to Trusted Locations).
  • When sharing a file, zip it or send via a method that doesn’t add the Mark of the Web (e.g., email attachment from a trusted sender).
  • If you distribute macros, sign them with a self-signed certificate (using SelfCert.exe that comes with Office) and add the certificate to Trusted Publishers.
  • Regularly back up your VBA code – export modules as .bas files so you can re-import them if a file gets corrupted.

Also, remember that macros cannot be undone with Ctrl+Z. Before running any macro that changes data, save a copy of the workbook (File > Save As) so you can revert if something goes wrong.

Frequently Asked Questions

Why does Excel say “Cannot run the macro” even after I enabled content?

If you enabled content but the error persists, the file may still be marked as blocked, or the macro itself has a compile error. Unblock the file via Properties, then open the VBA editor and press F5 to see the exact error message. Also verify the file is saved as .xlsm.

How do I unblock a macro file in Excel?

Right-click the file in Windows Explorer, select Properties, and on the General tab check the Unblock box. If the box isn’t there, the file isn’t blocked. For files that are still blocked, you can also clear the Mark of the Web by copying the file to a local drive (e.g., from Downloads to Documents) – sometimes that removes the flag.

What does “Macros are disabled” mean in the VBA editor?

That message appears when Excel’s security settings or a group policy prevent VBA from running. Go to File > Options > Trust Center > Macro Settings and ensure you haven’t selected “Disable all macros without notification.” If you’re on a managed computer, the policy may be enforced by IT.

Can I run a macro from a .xlsx file?

No. .xlsx files do not store VBA code. You must save the workbook as .xlsm (macro-enabled) or .xlsb (binary) to include macros. If you accidentally saved as .xlsx, the macros are lost unless you have a backup.

Why does my macro work on one computer but not another?

Differences in Excel versions, security settings, or missing references (like a specific ActiveX library) can cause this. On the other computer, check the Trust Center settings, and in the VBA editor go to Tools > References to ensure all required libraries are available. Also, if the macro uses a feature only in Excel 365, it won’t run on an older version.

Is it safe to enable all macros?

Enabling all macros globally is risky because macros can contain malicious code. Only do this temporarily on a trusted file. Instead, use Trusted Locations or digitally signed macros for a safer workflow. Always scan downloaded files with antivirus software.

Related

Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.

More in VBA & macros

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.