Office Settings & Configuration

Customize the Excel Ribbon with VBA and XML

John WilsonJohn Wilson Nov 18, 2026 875 views

Question details

The user wants to add custom Excel Ribbon controls and connect them to VBA actions.

How to Customize the Excel Ribbon with VBA and XML
Product
Microsoft Excel
Device & OS
not provided
Scenario
Create a custom Ribbon tab, group, or button for an Excel workbook or add-in.
Observed behavior
The desired Ribbon controls appear in Excel and run VBA callback procedures when selected.
Before you start

Save the workbook as an Excel Macro-Enabled Workbook (.xlsm) and install a Ribbon XML editor such as Office Custom UI Editor. Use macros only in files from trusted sources.

Solution 1Recommended

Add Ribbon XML and a VBA callback to an Excel workbook

Use this method to add a custom tab and button that runs VBA code when clicked.

The Ribbon is not exposed as a complete collection of VBA objects. Define the interface in Office Ribbon XML, then implement the named callbacks in VBA.

1
Prepare the workbook

In Excel, select File > Save As and choose Excel Macro-Enabled Workbook (*.xlsm). Close the workbook before opening it in the XML editor.

2
Insert a custom UI part

Open the .xlsm file in Office Custom UI Editor. Select Insert > Office 2007 Custom UI Part, then enter this XML: <customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"><ribbon><tabs><tab id="customTab" label="My Tools"><group id="customGroup" label="Actions"><button id="runReportButton" label="Run Report" onAction="RunReport"/></group></tab></tabs></ribbon></customUI>

3
Save the Ribbon definition

Use the editor's validation command to check the XML, then select File > Save and close the editor.

4
Add the VBA callback

Reopen the workbook in Excel and open the Visual Basic Editor. Select Insert > Module and add: Public Sub RunReport(control As IRibbonControl) MsgBox "The custom Ribbon button works." End Sub

5
Test the button

Save the workbook and enable macros if prompted and you trust the file. Select My Tools > Run Report to test the callback.

Add Ribbon XML and a VBA callback to an Excel workbook
Match callback names: The XML onAction value must match the public VBA procedure name. Replace the sample message with the action you want the button to perform.
Free Microsoft Office alternative

Work with Excel spreadsheets in WPS Office

WPS Office is a free, lightweight Office alternative with a familiar interface for opening and editing spreadsheets. It supports common Excel formats to help you move between applications, although Excel Ribbon XML and VBA customization may not work the same way in WPS.

Open and edit Microsoft Excel XLSX and XLS filesUse a familiar spreadsheet interface with Ribbon-style commandsWork with spreadsheets in a lightweight Office suiteMove common spreadsheet files between Excel and WPS Office
microsoft office alternative - wps office

Frequently Asked Questions

Can VBA alone create a custom Excel Ribbon tab?

No. Standard VBA does not provide a complete object model for creating Ribbon controls. Define the tab and controls in Ribbon XML, then use VBA procedures for their callbacks.

Why does my custom Ribbon button not run its macro?

Check that the button's onAction value matches a public VBA procedure name and that the procedure accepts an IRibbonControl parameter. Also check Excel's macro security prompt and enable macros only if you trust the workbook.

Where is the Ribbon XML stored?

The XML is embedded as a custom UI part inside the workbook or add-in file. Open the file in a Ribbon XML editor to view or change that part.

Can I use the same approach in an Excel add-in?

Yes. Embed the Ribbon XML in the add-in and place the matching public VBA callbacks in a standard module. Save and load the add-in in Excel before testing its controls.