Cannot Run Macro Error in Excel: Causes and Solutions

VBA & macros · Updated November 19, 2026

If Excel says it cannot run a macro, first confirm that the macro exists in an open, macro-enabled workbook and that Excel is allowed to run it. Then check the button or shortcut that launched it: the command may point to a macro that was renamed, moved, or is unavailable. The exact cause can also be a security setting, a blocked downloaded file, or an attempt to run VBA in Excel for the web.

What the error means

The message commonly reads, "Cannot run the macro … The macro may not be available in this workbook or all macros may be disabled." It combines two different possibilities: Excel cannot find the requested procedure, or Excel has prevented VBA from running. The first is a workbook, macro-name, or control-link problem; the second is usually a security or platform limitation. Treat the message as a starting point rather than proof that macros are disabled.

A macro is a VBA procedure saved in a workbook, an add-in, or Excel’s Personal Macro Workbook. A button, keyboard shortcut, or other command must be able to identify that procedure. If any link in that chain is missing, Excel may show the same error even when other macros run normally. For example, a workbook may contain working code while a shape button still refers to an earlier macro name.

Check whether the macro is available

Start by opening the workbook in the desktop version of Excel, then open the macro list. On Windows, press Alt+F8. On Mac, press Option+F8, or use the Developer tab’s Macros command. Look for the macro name mentioned in the error. The list can include procedures from other open workbooks, so note which workbook contains the relevant macro.

  • If the macro appears, select it and choose Run. If it runs directly but not from a button, the button assignment is a likely cause.
  • If it does not appear, check that the workbook containing the code is open and that the code is stored in the expected file.
  • If the macro is in an add-in or Personal Macro Workbook, confirm that the add-in is loaded or that the Personal Macro Workbook opened with Excel.

Not every VBA procedure appears in the standard macro list. A macro intended to be launched from that list or assigned to a typical worksheet button is generally a Public Sub procedure in a standard code module, with no required arguments. A Private procedure, a procedure that requires arguments, or an event procedure such as a worksheet-change handler is not a normal click-to-run macro. Event procedures run when their specified event occurs; they are not usually launched by selecting their name in the macro list.

If you have access to the code, press Alt+F11 on Windows to open the Visual Basic Editor; on Mac, use the Visual Basic Editor command on the Developer tab or Tools menu. Check the project tree for the workbook and inspect its modules. Do not change unfamiliar code just to make it appear: the workbook’s author or administrator may need to confirm how it is meant to run.

Review macro security without weakening protection

On Excel for Microsoft 365 for Windows, go to File > Options > Trust Center > Trust Center Settings > Macro Settings. The setting may block macros, notify you before enabling them, or follow an organization-managed policy. If Excel presents a security warning for a file you trust and expected to use, review the warning and follow your organization’s instructions. Do not enable all macros globally as a quick fix: macros can run code that changes files or accesses data.

Recent Microsoft 365 versions block many macros in files marked as coming from the internet. If the file came from a trusted source, close Excel and inspect the file in Windows File Explorer: right-click it, choose Properties, and look for an Unblock option on the General tab. This option is not shown for every file. Unblock only a file whose source and contents you trust; if it came from email or an unfamiliar site, ask the sender for a safe, verified copy instead.

A trusted location is another possible route for files that need macros regularly. In the Trust Center, review Trusted Locations and follow your organization’s rules before adding a folder. A trusted location changes how Office treats files in that folder, so do not use a broad folder such as Downloads or a shared folder that other people can write to. On a work-managed computer, policy may prevent changing macro settings or adding locations; contact the administrator rather than trying to bypass the restriction.

Check the workbook format and file location

An Excel workbook saved as .xlsx cannot store VBA code. If a macro-enabled file was saved as .xlsx, the VBA project is removed when that format is used, and a button referring to the removed macro can produce a run error. For a workbook that needs to retain VBA, use Excel Macro-Enabled Workbook (.xlsm) or Excel Binary Workbook (.xlsb). The older .xls format can also contain macros, though it is a legacy format.

To preserve the code, open the original file and use File > Save As, then choose .xlsm or .xlsb from the file-type list. Saving an .xlsx file as .xlsm later does not restore code that was already discarded; you need the original macro-enabled copy or a backup. If Excel displays a format warning when saving, read it carefully and choose the option that preserves VBA when that is the goal.

Also confirm that you opened the intended copy. A desktop shortcut, email attachment, or shared-drive link may open an older version with a different macro name or no code. Check the workbook title and file path, and compare the file with the version supplied by its owner. If the macro is supposed to be in a separate workbook, that workbook may need to remain open, or the macro may need to be referenced through its add-in.

Repair a button, shape, or shortcut assignment

If the macro runs from Alt+F8 but a worksheet control gives the error, the control may have a stale assignment. For a Form Control button or a shape, right-click it and choose Assign Macro. Select the correct macro from the list and confirm. A macro can be renamed while its old button assignment remains, so reassigning it is often enough. Test the control after saving a copy of the workbook.

Keyboard shortcuts can also be assigned to macros. In the Macro dialog, select the procedure and choose Options to inspect or change its shortcut. A shortcut may have been reassigned, or it may conflict with another command. Excel’s built-in shortcuts and macro shortcuts can differ across Windows and Mac, so check the workbook’s instructions rather than assuming the same key combination works on both systems.

ActiveX controls work differently from Form Controls. An ActiveX button typically runs code attached to its click event, rather than using the same Assign Macro workflow. On Windows, use Developer > Design Mode to inspect or edit an ActiveX control. If an ActiveX control is involved, check whether the workbook is in Design Mode and whether its event code exists. ActiveX controls are not supported in Excel for Mac, so a workbook that relies on them may need a Form Control, shape, or other cross-platform design.

Look for add-in, policy, and compatibility issues

If a macro is stored in an Excel add-in, verify that the add-in is installed and enabled. In Windows Excel, check File > Options > Add-ins, then review the Manage list at the bottom of the page and select Excel Add-ins or COM Add-ins as appropriate. A disabled or missing add-in can make its macro unavailable. If the workbook depends on a company add-in, ask its owner or IT support whether the current version is installed.

Some macros rely on external files, references, or Windows-specific code. A missing reference in the Visual Basic Editor can cause a different VBA error after a macro starts, but platform-specific code or unavailable components may also prevent a procedure from working as expected. For instance, code that calls a Windows API may need different declarations in 64-bit Excel or may not work on Mac. If the macro appears in the list but fails after starting, record the full error text and ask the code’s maintainer to check compatibility rather than repeatedly changing security settings.

On a managed work or school device, administrators can set policies that override a user’s Trust Center choices. If the macro settings are unavailable or a warning says the setting is managed, this is not a workbook repair you should try to evade. Provide IT with the workbook source, the exact message, and the steps that lead to it.

Know the limits of Excel for the web and Mac

Excel for the web does not run, create, or edit VBA macros. It can open a workbook that contains VBA, but selecting a VBA button or trying to run its macro requires opening the file in desktop Excel. In the web app, choose the option to open the workbook in the desktop application if available, then resolve any security prompt there. Office Scripts are a separate automation feature; they are not a way to execute an existing VBA macro in the browser.

Excel for Mac supports VBA, but not every Windows feature or control. ActiveX controls and Windows-only dependencies are important compatibility exceptions. If the same macro works on Windows but not Mac, identify whether the code uses an unsupported control, file path, reference, or operating-system call. A Form Control or shape linked to portable VBA may be more suitable when a workbook must be used on both platforms.

Frequently Asked Questions

Why does Excel say all macros may be disabled when I can run other macros?
The message is generic. The specific macro may be missing, private, stored in a closed workbook, or linked incorrectly even though Excel can run other code. Check the macro list and its workbook location before changing security settings.

How do I enable macros in Excel?
For a file you trust, respond to Excel’s security notification if one appears, or review File > Options > Trust Center > Trust Center Settings > Macro Settings on Windows. Settings vary by policy and version. Avoid enabling all macros for every file; ask an administrator if the setting is managed.

Can an .xlsx file run a VBA macro?
An .xlsx workbook cannot store a VBA project. Use the original .xlsm, .xlsb, or macro-containing .xls file. Renaming an .xlsx file or saving it as .xlsm does not bring back VBA that was removed during an earlier save.

Why does a macro work from the Macro dialog but not from its button?
The button may be assigned to an old or incorrect macro. For a Form Control or shape, right-click it, choose Assign Macro, and select the intended procedure. ActiveX controls use event code and need a different check on Windows.

Can I run an Excel macro in a browser?
No. Excel for the web does not execute VBA. Open the workbook in desktop Excel to run the macro, subject to the file’s security settings and platform compatibility.

Can I undo a macro if it changes the workbook?
Usually not with Ctrl+Z: running VBA clears Excel’s normal undo history. Save a separate copy before running unfamiliar or destructive code, and confirm what the macro changes with its author. A backup is safer than relying on Undo.

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.