Share via

How to fix cannot run macro

Isnaini Ni'mah 0 Reputation points
2026-06-02T06:57:56.5466667+00:00

User's image

How can i fix this? I try to assign macro but it didn't work. And thhe macro setting is already enabled

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

2 answers

Sort by: Most helpful
  1. Emmanuel Santana 39,635 Reputation points Independent Advisor
    2026-06-02T07:36:59.77+00:00

    Hello. One very important detail here is that your screenshot shows the workbook is saved as:

    RAPORT KLS VI SEM 2.xlsx
    

    A normal .xlsx file cannot properly store VBA macros. If the workbook originally contained macros and was later saved as .xlsx, Excel removes the VBA project but the buttons/shapes may still remain and continue trying to call the old macro, which produces this exact error.

    Please check this too:

    1. Save the workbook as a macro-enabled workbook:
    File → Save As → Excel Macro-Enabled Workbook (*.xlsm)
    

    Then close and reopen the file.

    1. Press:
    ALT + F11
    

    to open the VBA Editor.

    Check whether the procedure:

    Sub Shape31_Click()
    

    still actually exists. Also check inside:

    • Modules
    • Sheet objects
    • ThisWorkbook

    because button event procedures are sometimes stored in sheet modules rather than standard modules.

    1. In the VBA Editor, try:
    Debug → Compile VBAProject
    

    If there is a syntax error or broken reference anywhere in the project, Excel may prevent ALL macros from running even if the clicked macro itself is correct.

    1. Also check:
    Tools → References
    

    inside the VBA Editor.

    If anything is marked:

    MISSING:
    

    the VBA project may fail to load correctly.

    1. If the file came from another PC, WhatsApp, Telegram, Google Drive, or email, Windows may still be sandboxing it even with macros enabled globally.

    Try:

    • Right-click the file
    • Properties
    • Check “Unblock” if present

    or move the file into a Trusted Location in Excel.

    1. Another common cause is that the shape/button itself became corrupted or is still pointing to an old workbook reference after copying sheets between files. In that case:
    • delete the button
    • create a new one
    • reassign the macro manually

    Was this answer helpful?

    0 comments No comments

  2. AI answer

    2026-06-02T06:58:14.5033333+00:00

    The error means Excel cannot find or execute the macro that the shape/button is pointing to, or the macro is blocked.

    Try these steps in order:

    1. Confirm macros are enabled for this file
      • If the workbook was downloaded or emailed, save it locally.
      • In File Explorer, right‑click the workbook > Properties.
      • If there is an “Unblock” checkbox on the General tab (Security section), select it and click OK. This removes Windows’ block so Office can run macros from the file.
      • Reopen the workbook and test the button again.
    2. Check that the macro actually exists in this workbook
      • Open the workbook.
      • Press Alt+F11 to open the Visual Basic Editor.
      • In the Project pane, expand the workbook and look for a module or sheet that contains a procedure named Shape31_Click.
      • If the macro is missing (for example because the sheet was copied from another workbook), it must be recreated or copied into this workbook. The error “The macro may not be available in this workbook” matches this situation.
    3. Re‑assign the button to the correct macro
      • In Excel, right‑click the shape/button that should run the macro.
      • Choose Assign Macro.
      • In the list, select the correct macro (for example, the Shape31_Click procedure in this workbook) and click OK.
      • If the macro is not listed, it is not in this workbook or is in a hidden/disabled project; return to step 2.
    4. If the workbook or macro was copied from another file
      • When a worksheet is copied to a new workbook, assigned macros can still point back to the original workbook. In that case, either:
        • Move/copy the macro code into the new workbook, then re‑assign the button, or
        • Open the original workbook so the referenced macro is available.

    If macros are enabled, the file is unblocked, and the Shape31_Click procedure exists in this workbook and is correctly assigned to the shape, the button should run without this error.


    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.