How to Create an Excel Ribbon Button That Runs a VBA Macro
Question details
The user wants to create a custom picture-based Ribbon button in an Excel workbook that runs a specific VBA macro (e.g., Weekly Summary) and is only visible when the workbook is open.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Creating a custom user interface in an Excel workbook to trigger macros easily using Ribbon buttons.
- Observed behavior
- A custom Ribbon menu with a picture button needs to be integrated into the workbook to execute a VBA macro specifically tied to that workbook.
Ensure your Excel workbook contains the target VBA macro and is saved as a Macro-Enabled Workbook (.xlsm) before attempting to customize the Ribbon.
Create a Custom Ribbon Button Using RibbonX XML
The most robust way to add a custom ribbon button that only appears for a specific workbook is by modifying the workbook's RibbonX XML using a dedicated editor.
By embedding RibbonX XML directly into the workbook file, you ensure that the custom tab and macro button are exclusively loaded when that specific workbook is opened. This prevents the button from cluttering your workspace when working on unrelated spreadsheets.
Download and launch the open-source Office RibbonX Editor, which allows you to safely inject custom UI code into Microsoft Office files.
In the RibbonX Editor, click 'File' > 'Open' and select your target .xlsm workbook. Make sure the workbook is closed in Excel before doing this.
Right-click the document name in the left pane, select 'Insert Office 2010+ Custom UI Part', and input the XML structure for your custom tab, group, and button. Ensure you define an onAction callback, such as onAction="RunWeeklySummary".
Click 'Save' in the RibbonX Editor and close the application.
Open the workbook in Excel, press Alt + F11 to open the VBA Editor, and create a standard module. Define the macro with the IRibbonControl parameter: Sub RunWeeklySummary(control As IRibbonControl), followed by the code you want to execute.

Add a Macro Button to the Ribbon via Excel Options (Global)
If you do not need the button restricted to a single workbook, you can easily add macro buttons to the Ribbon directly from Excel settings without writing XML.
Run Macros Easily with WPS Office
WPS Spreadsheet provides excellent support for VBA macros, allowing you to automate tasks and customize your workspace efficiently without needing complex external XML editors.
- 1. Open your macro workbook: Launch WPS Spreadsheet and open your macro-enabled workbook (.xlsm).
- 2. Access Ribbon Customization: Navigate to 'Menu' > 'Options' and select 'Customize Ribbon' from the settings window.
- 3. Select the Macros category: Under the 'Choose commands from' dropdown, select 'Macros'.
- 4. Assign to a Ribbon group: Select your target macro, add it to a custom group on your Ribbon, and assign a clear icon for quick and easy access.

Frequently Asked Questions
Can I hide the macro button's feature description and supertip?
Yes, Ribbon feature descriptions and tooltips are controlled in the RibbonX XML using the 'supertip' and 'screentip' properties. In some cases, omitting them leaves a default blank description, but fully customizing or hiding them requires proper XML property formatting.
Why does my macro button say 'Cannot run the macro'?
This usually happens if the macro is located in a different workbook that is currently closed, the workbook isn't saved as a macro-enabled format (.xlsm), or your local macro security settings are blocking execution.
Can I create the Ribbon button using only VBA instead of XML?
While you can manipulate older standard CommandBars using pure VBA, creating true modern Ribbon buttons typically requires injecting RibbonX XML. You can use VBA to trigger the creation of XML dynamically, but the XML itself is required to define the Ribbon user interface.
How do I hide the custom Ribbon button when other workbooks are open?
By embedding the RibbonX XML directly into the specific workbook using the Office RibbonX Editor rather than modifying global Excel options, the custom tab or button is automatically restricted. It will only render when that exact workbook is active.




