Editor - Document Level


Creating an Excel Workbook with a Custom Ribbon

This ribbon customisation will only be visible when this particular workbook is open.
Create a new workbook and save it as a macro-enabled workbook (WorkbookRibbon-Editor.xlsm)
Open the Custom UI Editor by double clicking on the following file:

C:\Program Files\CustomUIEditor\CustomUIEditor.exe 

Open the Workbook

Select (File > Open) and browse to your WorkbookRibbon-Editor.xlsm file.


Add the customUI file

Before we can add the ribbon XML to this file you need to add the corresponding customui file.
It is this xml file that will contain the ribbon XML.
Right click on the entry and choose one of the following
Office 2010 Custom UI Part - Select this one if you are using Office 2010 or later (inserts customUI14.xml)
Office 2007 Custom UI Part - Select this one if you are using Office 2007 (inserts customUI.xml)


Add the Ribbon XML

Copy and paste the xml tags below into the window

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui"> 
  <ribbon startFromScratch="true">
    <tabs>
      <tab id="CustomTab" label="My Tab">
        <group id="SimpleControls" label="My Group">
          <button id="Button1" imageMso="HappyFace" size="large"
            label="Large Button"
            screentip="my long description"
            onAction="ThisWorkbook.MyMacro"/>
        </group>
      </tab>
    </tabs>
  </ribbon>
</customUI>

The tags will be formatted automatically once they have been pasted in.

Press the Validate button on the toolbar to check the XML is well formed.


Save Changes and Open

Select (File > Save) and close the CustomUI Editor.
Open the WorkbookRibbon-Editor.xlsm file


Running a Macro

When you click on the button you will see this message appear.

This is telling us that we have not linked an event handler to the pressing of the button.
Open the Visual Basic Editor and add the following code to the ThisWorkbook code module.

Public Sub MyMacro(ByRef control As Office.IRibbonControl) 
   Call MsgBox("Hello large button")
End Sub

Save the workbook and press the button.


See All Tabs

If you would like to see all your existing tabs then you need to change the startFromScratch property.
Change the following line at the top of the XML:

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui"> 
  <ribbon startFromScratch="false">

© 2019 Better Solutions Limited. All Rights Reserved. © 2019 Better Solutions Limited TopPrevNext