A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
The behavior typically occurs when the macro being run is not the one stored in the active workbook/module, but another macro with the same name or a different default macro in a different location (for example, in Personal.xlsb or another workbook). Excel/VBA can also misroute automatically-running procedures if they are stored “behind” sheets or ThisWorkbook instead of in a standard module.
Use these checks and adjustments:
- Verify where the macro is stored
- Press
ALT+F11to open the VBA editor. - In the Project Explorer, expand each VBAProject and check:
-
Modules(standard modules) -
Microsoft Excel Objects(Sheet1, Sheet2, ThisWorkbook, etc.).
-
- Confirm that the macro intended to run is in a standard module (for example,
Module1), not behind a worksheet orThisWorkbook, especially if it is an Auto_Open/Auto_Close or other automatically-running macro.
- Press
- Move automatically-running macros into a standard module
If the macro is an Auto_Open, Auto_Close, or other auto-running procedure and is currently behind a worksheet or ThisWorkbook, move it:
- In Project Explorer, activate the workbook that contains the code.
- On the Insert menu, select Module to create a standard module.
- Cut the macro code from the sheet or ThisWorkbook code window and paste it into the new module.
- Save the workbook and test again.
- Check for duplicate macro names across workbooks
- In the VBA editor, search for the macro name (
Ctrl+F) across the entire project or all open projects. - If the same macro name exists in multiple places (for example, in Personal.xlsb and in the active workbook), Excel may run the one in Personal.xlsb or another workbook.
- Either:
- Rename the macro in Personal.xlsb or the other workbook, or
- Qualify the macro call in the Quick Access Toolbar (QAT) assignment so it points explicitly to the correct workbook/module (for example,
MyWorkbook.xlsm!MyMacro).
- In the VBA editor, search for the macro name (
- Reassign the macro on the Quick Access Toolbar
- Right-click the ribbon or QAT and choose Customize the Quick Access Toolbar.
- Remove the existing button that runs the wrong macro.
- Add a new button and, when assigning the macro, ensure the correct workbook is selected in the “Macros in” dropdown and the correct macro name is chosen.
- Ensure macros are enabled
If macros are disabled or restricted, Excel may not correctly expose the intended macro and can show unexpected behavior.
- Enable the Developer tab if not already enabled.
- On the Developer tab, select Macro Security and ensure macro settings allow the macros in the workbook to run.
If after these steps the wrong macro still runs, focus on finding and renaming any duplicate macro names in Personal.xlsb or other open workbooks, and keep all auto-run procedures in standard modules rather than behind worksheets or ThisWorkbook.
References: