If Microsoft Excel says it cannot run a macro, first check that you are using the desktop version of Excel, the workbook is saved in a macro-capable format, and the macro is allowed by your security settings. Then confirm that the macro still exists under the name and location Excel is trying to run; the message can point to a blocked macro, a broken button assignment, or an error in the VBA code.
What the error means
Excel’s message that it cannot run a macro does not identify one single cause. A workbook button or shortcut may be calling a macro that has been renamed or deleted, Excel may have disabled the code for security, or the file may not contain VBA at all. A macro may also start and then stop because the code encounters an error. Those situations need different fixes, so note the full message and what you did immediately before it appeared.
One common wording is that Excel cannot run the macro because it may not be available in the workbook or all macros may be disabled. That points you toward two broad checks: whether the macro is present and callable, and whether Excel permits it to run. If the error names a particular workbook and macro, check that exact file and name rather than changing settings for every workbook.
Check the Excel version and workbook format
VBA macros run in the desktop versions of Excel for Windows and Mac, but they do not run in Excel for the web. Excel for the web can open and edit many workbooks containing VBA, but it cannot create, edit, or execute those VBA macros. Open the workbook in the desktop app if you need to run its code.
Next, check the file extension. An .xlsx workbook cannot store VBA macros. Macro-enabled workbooks commonly use .xlsm, while .xlsb and the older .xls format can also contain macros. If someone saved a macro-enabled workbook as .xlsx, Excel may have removed the VBA project during that save. Changing the extension back to .xlsm will not restore the lost code; ask for an original macro-enabled copy or restore a backup.
- In Windows, look at the file name in File Explorer or choose File > Info in Excel to confirm which workbook is open.
- If you need to preserve existing VBA, use File > Save As and select Excel Macro-Enabled Workbook (*.xlsm), rather than Excel Workbook (*.xlsx).
- If a file was sent to you, confirm that the workbook containing the macro is actually open. A button in one workbook may be trying to call code stored in a different workbook or add-in.
Review macro security without disabling protection
Excel blocks macros by default in many situations because VBA can make changes to files, access data, or perform other actions. Do not enable all macros simply to get past an error, especially for an unexpected attachment or a file from an unknown sender. First consider whether you expected the workbook, trust its source, and understand why it needs a macro.
In Excel for Microsoft 365 on Windows, inspect the setting at File > Options > Trust Center > Trust Center Settings > Macro Settings. The available options depend on your installation and organization’s policy. A setting that disables VBA without a notification will prevent macros from running; a notification-based setting can let you make a decision for an individual trusted file. If the controls are unavailable or greyed out, an administrator may have set them by policy. Ask your organization’s IT support rather than trying to bypass the restriction.
When Excel displays a security warning for a workbook you trust, read it before choosing whether to enable content. The exact warning and available choices can vary with the file’s source and your settings. Enabling a macro gives its code permission to run; it is not a routine repair step for every workbook. If you cannot verify the sender or purpose, leave the macro disabled and request a safe copy or an explanation.
Some trusted work processes use a trusted location: a folder Excel treats differently under the Trust Center settings. This can be suitable for controlled files managed by your organization, but it is not a good idea to designate a broad folder such as Downloads or your entire documents folder as trusted. Files placed there could run without the same prompts. Use only a restricted folder whose contents and access you can control.
Check whether Windows blocked a downloaded file
Windows may mark a workbook downloaded from the internet as coming from an untrusted source. Depending on the file and your organization’s settings, Excel can block its macros even if the general macro setting would otherwise allow them. Do not assume this is a fault in the workbook’s code: the block may be a deliberate security measure.
If the file came from a source you independently trust and you have verified it is the intended file, close Excel and inspect its Windows file properties. In File Explorer, right-click the workbook, choose Properties, and look on the General tab for an Unblock checkbox or button. If it is present, selecting it removes the internet-origin block for that file; reopen the workbook and review any Excel security prompt. This option may not appear on every file or Windows configuration. If the file is from an unknown source, do not unblock it just to make the macro work.
Confirm that the macro exists and the button points to it
If security is not the issue, confirm that Excel can see the macro. In Windows, press Alt+F8 to open the Macro dialog and look for the expected name. You can also use Developer > Macros. If the Developer tab is hidden, enable it through File > Options > Customize Ribbon and select Developer. On Mac, use Developer > Macros if the tab is available; the ribbon and shortcut details can differ by Mac version and keyboard settings.
If the macro appears in the list, select it and choose Run. Save a copy of the workbook first: macros cannot be undone with Ctrl+Z, and a macro may change many cells or files at once. If it runs from the dialog but not from a button, the button probably has an outdated assignment. In Windows, right-click the button or shape, choose Assign Macro, and select the correct macro. On Mac, Control-click the object to open its context menu; available controls can differ for form controls and shapes.
If the macro does not appear, consider where its code is stored. It might belong to another open workbook, an add-in, or the Personal Macro Workbook rather than the file you are looking at. The code may also be written as a private procedure or may require arguments, either of which can make it unavailable in the ordinary Macro dialog. If a workbook was updated or renamed, a button may still refer to an old workbook name or a macro that no longer exists. Ask the workbook’s author which file or add-in is required before editing unfamiliar code.
Look for VBA errors and compatibility problems
A macro can be present and permitted but still fail when it runs. If Excel opens the Visual Basic Editor and highlights a line, the issue may be a syntax or compile error, a missing reference, or a command the current system cannot use. If the error appears only after a particular action, note that action and the exact message; this can help distinguish a code problem from a security block.
For a trusted workbook, the author or a qualified VBA maintainer can inspect the code in the Visual Basic Editor. In that editor, Tools > References can reveal a reference marked MISSING, which can prevent code from compiling. Do not uncheck references at random: the macro may depend on the library, and changing references can create additional errors. A Windows macro that uses a Windows-only API or an ActiveX control may also need changes to work on Mac. Code that calls a 32-bit-only component may need updating for 64-bit Office.
If the workbook worked before an Office update or on another computer, compare the environments and required add-ins or components. A macro may rely on a particular folder path, printer, database driver, or other resource that is not available on the current device. The error may therefore come from an assumption in the code rather than a setting in Excel. Ask the author for an updated version instead of making broad security changes or running code you do not understand.
Know what differs on Mac and in the browser
Excel for Mac supports VBA, but not every Windows-specific feature is available there. ActiveX controls and some Windows API calls are examples of compatibility concerns. A workbook can therefore open on a Mac while a particular macro or control fails. Macro-security settings are managed through Excel’s preferences or settings, and the labels can vary between Mac releases; use the security controls for that version rather than following Windows-only instructions.
Excel for the web is different: it does not execute VBA macros. If a workbook opens in a browser, choose the option to open it in the desktop app, if your account and organization allow that, then try the macro there. A browser workbook’s inability to run VBA is not fixed by changing the file extension or clicking a button repeatedly. If your work must happen in a browser, ask whether the task can be handled with an alternative designed for that environment.
Safer troubleshooting order
Work from the least disruptive checks toward changes that affect security. This makes it easier to identify the real cause and avoids leaving Excel less protected than necessary.
- Record the full error text and confirm that the workbook is open in desktop Excel, not a browser.
- Check that the file is .xlsm, .xlsb, or another format capable of preserving VBA, and confirm the macro was not removed by an .xlsx save.
- Use the Macro dialog to see whether the expected macro is available, then test a trusted macro directly rather than through a possibly stale button.
- Review the file’s source and Excel’s security warning. Check organization policy or ask IT if settings are locked.
- If the macro begins but fails, give the exact error and steps to the workbook’s author or VBA maintainer.
Before any macro run that could alter important data, save a separate copy of the workbook. Ctrl+Z does not reverse VBA actions, so a backup is the practical way to recover from unintended changes. If a macro processes external files, confirm its intended folders and outputs before running it.
Frequently Asked Questions
Why does Excel say the macro may not be available in this workbook?
The macro might have been renamed or deleted, be stored in another workbook or add-in, or be unavailable because Excel disabled macros. Check the exact name in the Macro dialog, confirm the correct workbook is open, and review security settings only after verifying the file’s source.
Can an .xlsx file run a VBA macro?
No. The .xlsx format does not store VBA macros. Use a macro-enabled format such as .xlsm to preserve VBA. If the workbook was already saved as .xlsx and its code was removed, saving it again as .xlsm does not bring the code back.
Can Excel for the web run macros?
No. Excel for the web can work with some macro-enabled workbooks, but it cannot execute VBA. Open the workbook in desktop Excel for Windows or Mac if you need to run a VBA macro.
Should I enable all macros to fix the error?
No. Enabling all macros can expose your computer and data to harmful code. Verify the file and its source, use only the narrowest approved option for a trusted workbook, and contact IT if your organization manages the setting.
Why does a macro work on Windows but not on my Mac?
The code may depend on Windows-only features, such as an ActiveX control or a Windows API call, or on a component that is not installed on the Mac. The workbook’s author may need to adapt the code; changing the file format alone will not resolve a platform incompatibility.
Related
- Just Saved Excel File? Where to Find It and Recover It
- Excel Audit Trail: What It Tracks and How to View It
- Excel Shortcut to Insert a Row: Windows and Mac
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- Open Workbook VBA: Excel Methods and ExamplesTo open an Excel workbook with VBA, call Workbooks.Open and provide its full file path. For example, assign…
- Excel VBA: Open a Workbook Without Updating LinksTo open an Excel workbook with VBA and skip updating its external workbook links, pass UpdateLinks:=0 to Workbooks.Open.…
- VBA Loop Through Worksheets: Examples and TipsTo loop through every worksheet in an Excel workbook, declare a Worksheet variable and use For Each ws…
- Excel VBA Copy Range to Another Sheet: Methods and TipsTo copy a range to another worksheet with Excel VBA, qualify the source and destination sheets and use…
- Delete a Specific Row With a VBA MacroYes. In Excel for Microsoft 365 on Windows, a VBA macro can delete a specific worksheet row with…
- Print GMT Time Using Excel VBATo print the current GMT time with Excel VBA on Windows, call the Windows GetSystemTime API and send…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.