The error “Cannot run the macro ‘[MacroName]’. The macro may not be available in this workbook or all macros may be disabled” appears when Excel tries to execute a procedure attached to a button, shape, shortcut, or menu, but cannot find the code or lacks permission to run it. This error typically occurs because the button is still linked to an old file path after a workbook was renamed or moved, the macro was saved as Private or placed in a worksheet module instead of a standard module, or Excel’s Trust Center blocked macro execution.
Fast Fix:
Right-click the button or shape triggering the error, choose Assign Macro, and check the macro name. If the path references a previous file name (e.g.,
'OldFile.xlsm'!MacroName), select the macro under “This Workbook” and click OK. If running directly from the Macro dialog, verify the file is saved as.xlsmor.xlsband that macros are enabled in the Trust Center.
Diagnostic Flowchart: Identifying the Root Cause
Because this message bundles several distinct problems under one catch-all warning, use this diagnostic sequence to determine why Excel cannot locate or run the procedure:
Did the error occur when clicking a Button/Shape or from the Alt+F8 Menu?
│
├── Clicking a Button or Shape
│ └── Right-click button > "Assign Macro"
│ ├── Does the name include an external workbook path (e.g., 'C:\...\Book1.xlsm'!MySub)?
│ │ └── YES ──► Broken File Reference (Re-assign to active workbook).
│ └── Is the Macro Name box blank or pointing to a deleted Sub?
│ └── YES ──► Missing/Renamed Subroutine.
│
├── From the Macro Dialog (Alt + F8) or Ribbon
│ ├── Is the macro missing from the list entirely?
│ │ ├── Check VBA Editor: Is the Sub marked "Private Sub"?
│ │ ├── Check VBA Editor: Is the code in a Sheet/ThisWorkbook module instead of a Standard Module?
│ │ └── Check VBA Editor: Does the Sub take arguments (e.g., Sub Process(x As Integer))?
│ │
│ └── Is the macro listed, but clicking "Run" throws the error?
│ ├── Is the yellow Trust Center banner active ("Macros have been disabled")?
│ └── Was the macro stored in PERSONAL.XLSB and that file is disabled or missing?
Step-by-Step Fixes for Common Scenarios
1. Re-linking Hardcoded File Paths on Buttons and Shapes
When you copy a worksheet containing form buttons into a new file, or use Save As to create a new version of a workbook, Excel frequently keeps the absolute file path to the original file inside the button’s assignment property. When the original file is moved or closed, clicking the button fails.
- Right-click the button, icon, or shape that triggers the error.
- Select Assign Macro… from the context menu.
- Review the text in the Macro name box:
- Problem:
'Budget_2025.xlsm'!UpdateReport - Solution: Delete the single-quoted file name and exclamation point, leaving only
UpdateReport(or selectUpdateReportfrom the list under Macros in: This Workbook).
- Problem:
- Click OK, then save the file.
2. Resolving Macro Scope and Location (Standard vs. Object Modules)
For a macro to appear in Excel’s Run Macro dialog (Alt + F8) or be assigned to regular form controls, it must be declared as a Public Sub inside a Standard Module (Module1, Module2), not a Sheet or Workbook module.
- Press
Alt + F11to open the Visual Basic Editor (VBE). - In the Project Explorer (
Ctrl + R), inspect where your code is stored:- Wrong Location: Double-clicking
Sheet1 (Sheet1)orThisWorkbookand placing general subroutines there. Excel treats these as class objects, hiding them from the global macro list. - Correct Location: Click Insert > Module from the top menu. Place your code inside the newly created module (e.g.,
Module1).
- Wrong Location: Double-clicking
- Check the procedure header:
- If it reads
Private Sub MyMacro(), change it toPublic Sub MyMacro()(or simplySub MyMacro()). - If the subroutine accepts required parameters, such as
Sub FormatRange(rng As Range), Excel cannot run it directly from a button click without a parameterless wrapper macro:VBA' Wrapper macro that can be assigned to a button Public Sub RunFormatRange() Call FormatRange(Selection) End Sub
- If it reads
If your macro is running inside a background sheet module and fails when switching sheets, review Runtime Error 1004: Why ActiveSheet references cause failures in background macros.
3. Resolving Trust Center and Security Blocks
If Excel has disabled macro execution globally or blocked a file received over the internet, macros cannot run even if the code is present and correctly linked.
- Check the top of the worksheet below the Ribbon. If a yellow bar says “SECURITY WARNING: Macros have been disabled”, click Enable Content.
- If the file was downloaded from email, Teams, or the web, Windows may have applied a security block.
- Close Excel.
- Right-click the workbook file in Windows File Explorer and choose Properties.
- On the General tab, look for Security at the bottom. Check Unblock and click Apply > OK.
- Verify your Trust Center settings:
- Go to File > Options > Trust Center > Trust Center Settings > Macro Settings.
- Ensure it is set to Disable VBA macros with notification rather than Disable all macros without notification.
For persistent blocks on network shares or SharePoint sync locations, see “Macros have been disabled”: Troubleshooting the “Trusted Locations” security block. If working with macro security certificates, consult Digital Signatures: Fixing “The VBA project is not digitally signed.”
4. Restoring Missing Personal Macro Workbooks (PERSONAL.XLSB)
If you recorded a macro to your Personal Macro Workbook, the code resides in a hidden file named PERSONAL.XLSB. If that file was moved, deleted, or disabled by Excel after an unexpected shutdown, any shortcuts or custom Ribbon buttons tied to it will fail.
- Open Excel and go to the View tab on the Ribbon.
- In the Window group, check if the Unhide button is clickable. If
PERSONAL.XLSBis listed, select it and click OK to confirm it is loading. (You can hide it again once verified). - If
PERSONAL.XLSBdoes not load automatically, check if Excel placed it in the Disabled Items list:- Go to File > Options > Add-ins.
- In the Manage dropdown at the bottom, select Disabled Items and click Go….
- If
PERSONAL.XLSBis listed, select it, click Enable, and restart Excel.
For full troubleshooting of corrupted or missing startup files, see “Personal.xlsb” Errors: Troubleshooting the hidden startup workbook.
Common Confusion: Macro Unavailable vs. Runtime Errors
It is important to distinguish between an availability error and a runtime execution error:
- “The macro may not be available…” (Availability Error): Excel cannot locate the entry point or is blocked before execution begins. No code has run, and the VBA debugger will not open.
- “Runtime Error ‘1004’” or “Runtime Error ’91′” (Execution Error): Excel found the macro and began running it, but a specific line of code failed. The VBE displays an error dialog with a Debug button.
If your macro starts running but halts mid-execution on a specific command, refer to Troubleshooting VBA Runtime Error 1004: The Definitive Fix Guide to resolve the line-level defect.
Accidental File Conversion Warning
If a workbook containing macros was accidentally saved as a standard Excel Workbook (.xlsx), Excel permanently strips all VBA modules and UserForms during the save process.
To verify if your code still exists:
- Press
Alt + F11. - Check the Project Explorer window on the left.
- If the project contains only sheet objects and no
Modulesfolder, and the file extension is.xlsx, the macros were removed when the file was saved. - You must recover the code from a previous backup, an AutoRecover version, or an earlier
.xlsmcopy. Future versions must always be saved explicitly as Excel Macro-Enabled Workbook (.xlsm) or Excel Binary Workbook (.xlsb).