VBA: Create Custom Ribbon Tab & Buttons (RibbonX)

Excel tutorial showing how to create custom Ribbon tabs buttons groups and shortcuts for a personalized workflow
Make Excel work the way you want by creating your own custom Ribbon tabs and buttons. This step-by-step tutorial shows you how to customize the Excel Ribbon, create dedicated tabs and groups, add frequently used commands, and organize tools for faster access. Learn how custom Ribbon layouts can streamline repetitive workflows, improve productivity, and make specialized Excel workbooks easier to use. Ideal for Excel power users, analysts, developers, trainers, and professionals who want to build a more efficient and personalized Excel interface.

You wrote a great macro, but nobody can find it. It hides behind Alt+F8 or a stray shortcut. Your users deserve a real button instead. A custom ribbon tab gives every macro a clear home, with a label and an icon. Excel has no built-in ribbon editor, though. Instead, you define the ribbon with RibbonX XML stored inside the workbook, then wire each button to a macro.

This guide shows how to build a custom ribbon step by step. First, it explains where the XML lives and how it maps to buttons. Then it walks through the callback that makes a button run code. Real examples and a full troubleshooting section follow. By the end, your macros will sit on their own tab.

How the Ribbon Is Defined

The ribbon layout is just XML inside the file. A tab holds groups, and a group holds buttons. Each button names a macro to run through onAction. Notably, the structure reads like the ribbon looks. The infographic below shows the mapping.

RibbonX XML maps straight onto the ribbon <tab label="My Tools"> <group label="Reports"> <button id="b1" label="Run" onAction="RunIt"/> </group> </tab> My Tools Home Insert ... Reports Run onAction calls a VBA Sub: Sub RunIt(control As IRibbonControl)

Excel does not let you edit this XML directly. So you use a free tool called the Office RibbonX Editor. It opens the workbook, shows the XML, and validates it. Then Excel reads your layout the next time it opens.

Save as a macro file first. A custom ribbon needs macros, so use the .xlsm or .xlsam format. A plain .xlsx cannot store the code your buttons call. Therefore save and close before you add the XML.

Set Up the RibbonX Editor

The editor is small and free to download. It opens your closed workbook and reveals the customUI part. From there you paste and validate the ribbon XML. Because it checks your tags, it catches most mistakes early.

First-time setup: 1. Save the workbook as .xlsm, then close it. 2. Open it in the Office RibbonX Editor. 3. Insert a customUI part from the menu. 4. Paste your ribbon XML into that part. 5. Validate, save, then reopen in Excel. The editor never touches your sheets or data. It only writes the ribbon definition into the file.

Example 1: A Minimal Tab and Button

Start with the smallest ribbon that works. It has one tab, one group, and one button. This proves your setup before you add more. So paste it, save, and reopen Excel.

The starter XML: <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui"> <ribbon> <tabs> <tab id="tab1" label="My Tools"> <group id="g1" label="Reports"> <button id="b1" label="Run Report" size="large" onAction="RunReport"/> </group> </tab> </tabs> </ribbon> </customUI> A new tab named My Tools now appears. It holds one large button ready to wire up.

Example 2: Wire the Button to a Macro

A button does nothing until a macro backs it. The onAction name must match a VBA sub. Crucially, that sub needs a special signature. It must accept an IRibbonControl argument.

The callback in a standard module: Sub RunReport(control As IRibbonControl) MsgBox "The report is running." ' your real code goes here End Sub The name RunReport matches the onAction value. Without the control argument, the button fails silently. So always include it, even if you ignore it.

Example 3: Add a Built-In Icon

A button looks better with a real icon. Excel ships thousands of built-in images. You reference one by its imageMso name. Therefore your tab matches the native look.

Attach an icon by name: <button id="b2" label="Refresh" imageMso="RefreshAll" onAction="RefreshData"/> The imageMso value is Microsoft's own icon id. For example, RefreshAll shows the familiar refresh icon. You can find these ids in imageMso gallery lists online.

Example 4: Group Several Buttons

Real tools need more than one button. A group keeps related actions together. You simply add more buttons inside it. As a result, the tab stays tidy and clear.

A group with three actions: <group id="g2" label="Data"> <button id="b3" label="Import" onAction="ImportData"/> <button id="b4" label="Clean" onAction="CleanData"/> <button id="b5" label="Export" onAction="ExportData"/> </group> Each button points to its own macro. Group labels help users scan the tab quickly.

Example 5: Enable a Button Dynamically

Sometimes a button should turn on or off. A getEnabled callback decides that at runtime. You then refresh the ribbon to apply the change. This keeps the tab in step with your data.

Control state with a callback: <button id="b6" label="Submit" getEnabled="IsReady" onAction="Submit"/> ' VBA: Sub IsReady(control As IRibbonControl, ByRef enabled) enabled = (Range("Status").Value = "OK") End Sub Call ribbon.Invalidate to re-run the callback. So the Submit button enables only when the status is OK.

Troubleshooting Custom Ribbons

All three problems below are the most common. Each has a clear cause and a quick fix.

The button does nothing when clicked

Usually the callback has the wrong signature. A ribbon macro must accept an IRibbonControl argument. Without it, Excel cannot call the sub, so nothing happens. First, open the callback and check its first line. Then make sure it reads control As IRibbonControl. Also confirm the onAction name matches the sub name exactly. With both in place, the button runs your code every time.

The custom tab never appears

This often means macros are disabled for the file. A ribbon tied to macros will not load then. First, check the yellow security bar and enable content. Next, confirm the file is saved as .xlsm, not .xlsx. Then validate the XML in the RibbonX editor, since one bad tag hides the whole tab. After a clean validation and a reopen, the tab appears.

An icon shows as blank

This means the imageMso name is wrong or unknown. Excel ignores an icon it cannot find and shows nothing. So double-check the exact spelling and capitalisation. The ids are case sensitive, which trips many people up. Then compare your value against a published imageMso list. Once the name matches a real icon, it renders correctly.

Frequently Asked Questions

  • Can I edit the Excel ribbon without extra tools?+
    Not for a code-backed tab, unfortunately. Excel has no built-in RibbonX editor. So most people use the free Office RibbonX Editor. It opens the file and validates the XML for you.
  • Why must a ribbon macro have IRibbonControl?+
    Because Excel passes the clicked control to the sub. The callback signature must accept that argument. Without it, the macro cannot run from the button. So include control As IRibbonControl every time.
  • What file type do I need for a custom ribbon?+
    You need a macro-enabled format, such as .xlsm. A plain .xlsx cannot store the macros your buttons call. Therefore save as .xlsm before adding the XML. An add-in .xlam works too.
  • How do I add an icon to a button?+
    Use the imageMso attribute with a built-in icon id. For example, imageMso="RefreshAll" shows the refresh icon. The ids are case sensitive, so spell them exactly. Published galleries list every available name.