logo
search
VBA & Macro Problems

How to Fix Cannot Run Macro Error in Macro-Enabled Excel Workbooks

Emma BrownEmma Brown Oct 21, 2026 869 views

Question details

The user needs to resolve an issue where Excel displays an error stating that a macro cannot run or is disabled, even though macros are enabled in the workbook settings.

How to Fix 'Cannot Run Macro' Error in Macro-Enabled Excel Workbooks
Product
Microsoft Excel
Device & OS
not provided
Scenario
Attempting to execute a macro by clicking an assigned button or shape in a macro-enabled workbook.
Observed behavior
Excel blocks the execution with an error indicating the macro cannot run or might be disabled, despite the workbook being saved in a macro-supporting format with macros enabled.
Before you start

Ensure your file is explicitly saved as an Excel Macro-Enabled Workbook (.xlsm) and that you have enabled macros in the Excel Trust Center before modifying the VBA code.

Solution 1Recommended

Verify VBA Procedure and Reassign Macro Button

Check if the macro exists in the correct standard module, ensure it is public, and reassign it to the button to fix broken name references.

Often, this error occurs if the button is assigned to a macro name that was recently changed, deleted, or moved to a different module. If the macro is marked as Private or has compile errors, Excel will also fail to run it.

1
Open the VBA Editor

Press ALT + F11 on your keyboard to open the Visual Basic for Applications (VBA) Editor.

2
Locate the Standard Module

In the Project Explorer pane on the left, find the standard module containing your macro (for example, MDL_DM_00_Setup_Cmd) and double-click to open it.

3
Verify Procedure Status

Ensure your macro (e.g., 'btnclick') is present, declared as a 'Public Sub', and does not have any syntax errors. Go to Debug > Compile VBAProject to check for compile issues.

4
Reassign the Macro

Return to your Excel worksheet. Right-click the button or shape that triggers the error and select 'Assign Macro' from the context menu.

5
Update the Reference

Select the correct macro name from the list provided in the Assign Macro dialog box and click 'OK'. Test the button again.

Verify VBA Procedure and Reassign Macro Button
Public vs. Private Macros: Only Public Sub procedures can be assigned to shapes or buttons in Excel. If your macro is declared as 'Private Sub', it will not appear in the Assign Macro list and will cause execution errors if manually linked.
WPS Macro Support

Easily Manage and Run Macros with WPS Office

WPS Office provides robust support for VBA and macro-enabled workbooks. You can easily enable, edit, and run macros in a highly compatible and secure spreadsheet environment.

  1. 1. Open Macro Workbook: Launch WPS Spreadsheet and open your .xlsm macro-enabled file.
  2. 2. Access Developer Tools: Navigate to the 'Developer' tab in the top ribbon to access macro settings.
  3. 3. Inspect VBA Code: Click 'Visual Basic' or 'Macros' to view your procedures, standard modules, and troubleshoot any broken code references.
  4. 4. Assign Macro to Objects: Right-click any shape or control button on your sheet and choose 'Assign Macro' to properly link your VBA scripts.
Fully compatible with Microsoft Excel .xlsm files and VBA macros.Lightweight architecture ensures heavy macro files load quickly without lagging.Intuitive developer tools for editing VBA code, debugging modules, and assigning macros.
microsoft office alternative - wps office

Frequently Asked Questions

Why does Excel say my macro is disabled when I already clicked Enable Content?

This commonly happens when a button is trying to run a macro that Excel cannot locate. If the macro was renamed, moved to a different standard module, deleted, or changed to Private, clicking the button triggers the generic 'macro cannot run' error.

Do I need to save my file as .xlsm to run macros?

Yes, standard Excel workbooks (.xlsx) automatically strip out all VBA code when saved. You must save the file as an Excel Macro-Enabled Workbook (.xlsm) or an Excel Binary Workbook (.xlsb) to retain and run macros.

How do I check for compile errors in my VBA code?

Open the VBA Editor by pressing ALT + F11, click on the 'Debug' menu at the top, and select 'Compile VBAProject'. If there are errors, the editor will highlight the problematic lines of code so you can correct them before running the macro.

Can I edit and run VBA macros in WPS Office?

Yes, WPS Office supports VBA. You can open Microsoft Excel .xlsm files, access the Developer tab, edit standard modules in the Visual Basic Editor, and run macros with excellent cross-platform compatibility.