If you want to display custom ribbon tabs when the workbook is open, follow these steps. Works fine in Excel 2019 and Windows 64-bit.
- Create a .xlsx file.
- Copy and paste macro code below into the normal module.
Option Explicit Public MyRibbon As IRibbonUI 'Callback for customUI.onLoad Sub ribbonLoaded(ribbon As IRibbonUI) Set MyRibbon = ribbon MyRibbon.ActivateTab ("customTab") End Sub 'Callback for customButton onAction Sub Callback(control As IRibbonControl) MsgBox "Hello world!" End Sub
- Save as Excel Macro-Enabled Workbook(*.xlsm) file.
- Close the .xlsm file.
- Open the file in Office RibbonX Editor.
- From the Insert menu, choose Office 2010+ Custom UI Part.
- Copy and paste RibbonX code below into customUI14.xml and save.
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="ribbonLoaded"> <ribbon> <tabs> <tab id="customTab" label="MyTab" insertAfterMso="TabHome"> <group id="customGroup" label="Custom Tab"> <button id="customButton" label="Custom Button" imageMso="HappyFace" size="large" onAction="Callback"/> </group> </tab> </tabs> </ribbon> </customUI>
- Open the file, the custom ribbon tab (MyTab) is activated.