VBA & Macro Problems

How to Run a Macro in Another Excel Workbook from a Custom Ribbon

Khadija KhanKhadija Khan Nov 3, 2026 869 views

Question details

The user wants to trigger a macro stored in a separate network .xlsm workbook via a custom ribbon button located in their PERSONAL.XLSB file.

How to Run a Macro in Another Excel Workbook from a Custom Ribbon
Product
Microsoft Excel
Device & OS
not provided
Scenario
Attempting to execute an external macro from a custom ribbon button mapped in a personal macro workbook.
Observed behavior
The Application.Run command fails with an error when triggered from the custom ribbon, even though the exact same command runs successfully from the VBA Immediate window.
Before you start

Ensure that macros are enabled in your Trust Center settings and verify that the target workbook containing your macro is not corrupted.

Solution 1Recommended

Correct Application.Run Syntax and Workbook Status

Ensure the exact syntax is used for referencing external workbooks and that the target workbook is properly opened without naming conflicts.

When calling macros across different workbooks, Excel requires exact reference paths, particularly when spaces are involved in the workbook name. Additionally, the target workbook must be open, and there cannot be another workbook with the same name already open in the background.

1
Format the Application.Run command correctly

In your VBA code, format the call using single quotes around the workbook name, followed by an exclamation mark and the macro name. Example: Application.Run "'Target Workbook.xlsm'!MacroName".

2
Programmatically open the target workbook

Add code to check if the target workbook is open. If it is closed, use Workbooks.Open to open the specific .xlsm file before the Application.Run command executes.

3
Prevent duplicate filename conflicts

Excel cannot open two workbooks with the same name. Ensure no duplicate file is currently active or hidden in the background before running the macro.

Correct Application.Run Syntax and Workbook Status
Immediate Window Difference: The Immediate window often works because it executes within the context of the active workbook, while ribbon clicks operate from the context of PERSONAL.XLSB, requiring more explicit path definitions.
Free Microsoft Office alternative

Use WPS Office for Reliable Macro and VBA Support

If you frequently encounter ribbon and macro execution errors in Microsoft Excel, consider switching to WPS Office. It provides robust support for VBA macros and offers seamless compatibility with Excel formats in a lightweight package.

  1. 1. Download and install: Download WPS Office from the official website and complete the installation process.
  2. 2. Open your macro workbooks: Launch WPS Spreadsheet and seamlessly open your existing .xlsm or .xlsb files.
  3. 3. Access the Developer tab: Enable the Developer tab to manage your VBA code, run macros, and customize your workflow without execution errors.
Fully compatible with Microsoft Excel formats including .xlsx, .xlsm, and .xlsbRobust VBA and macro support for automating repetitive workflows easilyLightweight application that runs smoothly without consuming excessive system resourcesFree to download and use with a highly intuitive, tabbed user interface
microsoft office alternative - wps office

Frequently Asked Questions

Why does Application.Run work in the Immediate window but not from the ribbon?

The Immediate window executes code in the context of your currently active VBA project. A custom ribbon button, especially one mapped to PERSONAL.XLSB, may lose this context or face stricter security barriers when attempting to call code in an external network file. Explicitly defining the workbook path and ensuring exact string syntax usually resolves this.

Can I run a macro from a closed workbook using Application.Run?

No, Excel requires the target workbook to be open before running a macro inside it. You must either open it manually beforehand or include VBA code (like Workbooks.Open) in your primary macro to open the target file before triggering the Application.Run command.

What causes the 'cannot open two workbooks with the same name' error?

Excel restricts users from opening two workbooks that share the same filename simultaneously, even if they are located in completely different folders or network drives. To fix this, you must locate and close the conflicting workbook before attempting to open the new one or run the macro.