Excel Macro Execution Fails: The macro may not be available in this workbook or all macros may be disabled

How to solve issues with Ui Path + VBA macros bots?

Issue Description

Excel macro execution fails with the following error:

"The macro may not be available in this workbook or all macros may be disabled."

Resolution

The error may be caused by several common issues. Follow the steps below to troubleshoot and resolve it:

  1. Enable Macros:
  • Open Excel manually → Navigate to File → Options → Trust Center → Trust Center Settings → Macro Settings.
  • Select Enable all macros (recommended for testing purposes).
  • Check the option Trust access to the VBA project object model under Macro Settings.
  • Save the changes and restart Excel.

  1. Verify Macro Location:
  • Open the workbook in Excel and press Alt+F11 to open the VBA editor.
  • Confirm that the macro is under the correct module (e.g., Module1) and not incorrectly placed inside Sheet1 or ThisWorkbook, unless the macro is being invoked with the proper prefix.
  • Ensure the macro is named correctly. For example:
    • If the macro is named MyMacro, it must be called exactly as "MyMacro".
    • If the macro resides in Module1, it can be alternatively called as "Module1.MyMacro".

  1. Verify File Format:
  • Ensure the workbook is in .xlsm format (macro-enabled workbook).
  • If the workbook is saved in .xlsx format, macros are stripped out, and cannot be accessed. Save the file as .xlsm to enable macro functionality.

  1. UiPath Activity Configuration:
  • Macros cannot run when using Workbook activities in UiPath as these do not launch Excel directly.
  • Use the Excel Application Scope activity to ensure the Excel application is invoked and active during macro execution.

  1. Validate File Location:
  • Files originating from email attachments, downloads, or network shares may open in Protected View, which would prevent macros from executing.
  • Move the file to a trusted location or add the folder path to Trust Center → Trusted Locations in Excel.

  1. Excel Version Compatibility (32-bit vs. 64-bit):
  • Ensure the macro compatibility aligns with the bit version of the installed Excel application (32-bit or 64-bit).
  • Test the macro manually in Excel to verify if any compatibility errors are encountered.