Skip to main content

Show Custom Ribbon Tabs When Workbook is Open

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.

  1. Create a .xlsx file.
  2. 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
  3. Save as Excel Macro-Enabled Workbook(*.xlsm) file.
  4. Close the .xlsm file.
  5. Open the file in Office RibbonX Editor.
  6. From the Insert menu, choose Office 2010+ Custom UI Part.
  7. 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>
  8. Open the file, the custom ribbon tab (MyTab) is activated.

Leave a comment

Your email address will not be published. Required fields are marked *

Format your code: <pre><code class="language-vba">place your code here</code></pre>