Excel vba runs the wrong macro

Ron and Heather McLaren 0 Reputation points
2026-03-13T17:08:44.75+00:00

I open an Excel workbook (on windows 11) open VBA, click on a macro in the list of modules that VBA shows me, click the icon to run it. Then vba proposes to run a different macro - one I almost never use. I think there is a mismatch between the workbook and the xlsb file, but I cannot figure it out. Can you help? I can make it work if I open the macro code first, but that would be inconvenient: I want to initiate macros from the quick access toolbar.

Ron

Microsoft 365 and Office | Excel | For home | Windows
0 comments No comments

1 answer

Sort by: Most helpful
  1. AI answer

    2026-03-13T17:09:08.43+00:00

    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:

    1. Verify where the macro is stored
      1. Press ALT+F11 to open the VBA editor.
      2. In the Project Explorer, expand each VBAProject and check:
        • Modules (standard modules)
        • Microsoft Excel Objects (Sheet1, Sheet2, ThisWorkbook, etc.).
      3. Confirm that the macro intended to run is in a standard module (for example, Module1), not behind a worksheet or ThisWorkbook, especially if it is an Auto_Open/Auto_Close or other automatically-running macro.
    2. 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:
      1. In Project Explorer, activate the workbook that contains the code.
      2. On the Insert menu, select Module to create a standard module.
      3. Cut the macro code from the sheet or ThisWorkbook code window and paste it into the new module.
      4. Save the workbook and test again.
    3. Check for duplicate macro names across workbooks
      1. In the VBA editor, search for the macro name (Ctrl+F) across the entire project or all open projects.
      2. 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.
      3. 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).
    4. Reassign the macro on the Quick Access Toolbar
      1. Right-click the ribbon or QAT and choose Customize the Quick Access Toolbar.
      2. Remove the existing button that runs the wrong macro.
      3. 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.
    5. Ensure macros are enabled If macros are disabled or restricted, Excel may not correctly expose the intended macro and can show unexpected behavior.
      1. Enable the Developer tab if not already enabled.
      2. 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:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.