Customize the Word 2007 Ribbon User Interface (UI)

Article contributed by Greg Maxey

"Shock and dismay" is a phrase well suited to describe the reaction of many intermediate and advance Word users upon their  introduction to the Ribbon UI in Word2007.  Shock that Microsoft would completely eliminate the familiar menus and toolbars, and dismay that it seemed impossible to customize or edit the Ribbon UI to suit their particular needs.

Be that as it may, I think that the Ribbon UI is here to stay and serious users should learn to get along with it.  Since its introduction there has been a plethora of third party applications developed that allow users to perform limited Ribbon UI customization or attempt to mimic the "classic" menu and toolbar scheme of earlier Word versions.  Fellow MVP Bill Coan provides a review of two popular applications  in the MVP FAQ article: Customizing the Office 2007 user interface

This article presents my attempt to show you how you can customize the Ribbon UI without resorting to "commercial" third party Add-Ins (i.e., Add-Ins that you have to pay for).  The methods presented here will help to show you how to regain complete control of your Ribbon UI look and functionality.

The ribbon is customized using an XML script.  From here on I will "try" to refer to this script as RibbonXML.  While you don't have to be a rocket scientists to customize the Ribbon UI, you do have to be willing roll up your sleeves and learn just a little about RibbonXML structure and the ribbon controls themselves.

An excellent resource to gain some technical background and information about Ribbon customization is available in a series of Microsoft articles titled "Customizing the Office2007 Fluent Ribbon for Developers (Parts 1, 2, and 3):"

[Comment added 31-May-2022 by Lene Fredborg: Unfortunately, the articles that were originally available on msdn2.microsoft.com have been removed. The links below point to copies of the articles found on the Internet Archive WayBackMachine. The original URLs were: Part 1: http://msdn2.microsoft.com/en-us/library/aa338202.aspx, Part 2: http://msdn2.microsoft.com/en-us/library/aa338199.aspx, Part 3: http://msdn2.microsoft.com/en-us/library/aa722523.aspx]

Customizing the 2007 Office Fluent Ribbon for Developers (Part 1 of 3) - from WayBackMachine

Customizing the 2007 Office Fluent Ribbon for Developers (Part 2 of 3) - from WayBackMachine

Customizing the 2007 Office Fluent Ribbon for Developers (Part 3 of 3) - from WayBackMachine

In my opinion the real value of these articles, once you see how the ribbon is customized here, is as a reference for exploring additional ribbon controls and their methods, attributes and callbacks.

In the examples that follow, I perform the customization using the Office 2007 Custom UI Editor and a Word VBA Template Add-In.  I used this approach because the Custom UI Editor automatically builds the Open Office XML file relationships and makes them transparent to you the user, the approach doesn't require any expensive additional developer's software like Visual Studio, and any specialized customization involving ribbon callbacks can be done using VBA.

The Office 2007 Custom UI Editor is available for free download from the OpenXMLDeveloper.org: Custom UI Editor [Lene Fredborg, 19-Aug-2019: Removed outdated link to http://openxmldeveloper.org/blog/b/openxmldeveloper/archive/2009/08/06/7293.aspx - NEW LINK ADDED BELOW]

[New link added by Lene Fredborg, 19-Aug-2020] You can download an improved version of the Custom UI Editor from the following page (read the information on the page): https://github.com/fernandreu/office-ribbonx-editor/releases/tag/v1.7.0.

Using the methods described here, ribbon customization can be applied to a single document, all documents based on a particular Word template, or globally using a Word template Add-In.

Ok, enough background.  Now on to the process of customizing the Ribbon UI.

 


The first example is very basic.  Here I will show you how to "hide" a single built-in control on the ribbon.  Lets hide the "Macros" group from the "View" tab.  You might want to do this to make room for a different control.

Ribbon before customization

The steps for making this customization are outlined below

- Open Word.  Create and save a new macro enabled template.  For this example I created and saved a template named  "MVP FAQ Example A"

- Close the template and close Word.

- Start the Office 2007 Custom UI Editor application and open the template file that you just created.

A blank RibbonXML slate appears

- Copy and then paste the following RibbonXML script in the CustomUI window.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<
customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
<
ribbon>
  <
tabs>
    <
tab idMso="TabView">
      <
group idMso="GroupMacros" visible="false" />
    </
tab>
  </
tabs>
</
ribbon>
</
customUI>

The complete workings and writing of the RibbonXML script shown above is beyond the

scope of this page.  However, I hope after looking at it closely that you will see that it consists of a well ordered hierarchical structure of instructions.   The ribbon element contains one or more tab controls, the tab controls contain one or more group controls.  As you will see later, group controls can contain additional controls such as buttons, splitButtons, dropdowns, menus, separators, etc.. Each element (and its attributes) is wrapped in XML tags and wrapped within its parent element.   It is a little like Russian dolls or Chinese eggs, where the smaller pieces fit neatly into the larger pieces.  All work together to define your ribbon's look and functionality.

:old:Note: You can't physically remove the built-in controls on the ribbon.  Instead you use the "visible" attribute of the control to determine if that control is shown on the ribbon.

In the RibbonXML script above we have created a set of instructions that:

  1.  Hides the built-in GroupMacro control on the built-in View tab.

See if you can follow how these instructions were defined in the RibbonXML script above.

- Save and close the CustomUI file.  

:old:Tips: 

      The RibbonXML script shown above is validated against the schema definition for ribbon extensibility.  When you begin to create your own RibbonXML script with the Custom UI Editor it is a good practice to always validate your script against the schema definition before closing the editor.  The schema definition provides the rules for creating valid hierarchical instructions for customizing the ribbon.  You can download and review a a copy of the schema definition from the MSDN website: CustomUI Schema [Lene Fredborg, 04-Jun-2019: Removed outdated link to http://www.microsoft.com/downloads/]      

      Additionally, use the Office Menu>Word Options>Advanced>General and select "Show add-in user interface errors."

      Both these actions can save you possible frustration as you explore and experiment with ribbon customization.

After creating and saving the RibbonXML script using the Custom UI Editor, the template's Open Office XML format file will contain a new CustomUI folder with a CustomUI.xml file that is used to define the custom ribbon. 

As I stated earlier, this example employs a Word Template Add-In.  When the Add-In is loaded Word will look inside the zip-format XML file structure for a folder called _rels, and then looks inside that folder for a file called .rels, Word then reads that file to find out where any customizations are stored and executes customization instructions accordingly.

The beauty of the Office 2007 Custom UI Editor is the relationships with other parts of the Open Office XML file container are created for you automatically.  If you are interested in exploring and creating the relationships manually then read those articles linked above.

- Place the template in your Word Startup folder and start Word.  Your ribbon should now appear modified as shown above.

 

 


The next example will expand on what you have seen above.  Lets use the built-in Home tab and remove, rearrange and add controls.  The Home tab contains a group labeled "Clipboard" on the left hand side and a group labeled "Editing" on the right hand side.  I want to combine these groups into a single group labeled "Editing and Clipboard" located on the left side of the ribbon as shown in the illustration below. 

Once again:

- Open Word.  Create and save a new macro enabled template.  For this example I created and saved a template named  "MVP FAQ Example 1"

- Close the template and close Word.

- Start the Office 2007 Custom UI Editor application and open the template file that you just created.

 - Paste the following RibbonXML script in the CustomUI window.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<
customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
<
ribbon>
  <
tabs>
    <
tab idMso="TabHome">
      <
group idMso="GroupEditing" visible="false" />
      <
group idMso="GroupClipboard" visible="false" />
      <
group id="CustomGroup" label="Editing and Clipboard" insertBeforeMso="GroupFont">
        <
splitButton idMso="PasteMenu" size="large" />
        <
button idMso="Cut" />
        <
button idMso="Copy" />
        <
control idMso="FormatPainter" />
        <
separator id="Sep1" />
        <
button idMso="FindDialog" />
        <
button idMso="ReplaceDialog" />
        <
menu idMso="SelectMenu" />
        <
dialogBoxLauncher >
          <
button idMso="ShowClipboard" />
        </
dialogBoxLauncher>
      </
group>
    </
tab>
  </
tabs>
</
ribbon>
</
customUI>

:old:Reminder: You can't physically remove or edit built-in controls on the ribbon.  Instead you use the "visible" attribute of the control to determine if that control is shown on the ribbon.

In the RibbonXML script above we have created a set of instructions that:

  1.  Hides the built-in GroupClipboard and GroupEditing controls on the built-in Home tab.

  2. Creates a new custom group "Editing and Clipboard" positioned before the built-in GroupFont.

  3. Adds built-in buttons, a control, a menu , and a dialogBoxLauncer to the new custom group along with a custom separator.

See if you can follow how these instructions were defined and arranged in the RibbonXML script.

:old:Tip: "idMso" is the fixed internal tag for built-in controls.   The idMso must match a valid control name.  You can determine the name of most of the built-in controls using the Office Button>Word Options>Customize and scrolling your mouse over the built-in in command.  The idMso appears in screen tip in parenthesis e.g., Popular Commands | File (FileSave).  Additionally, a  complete list of Ribbon UI control names and types can be downloaded from Microsoft:
List of Control IDs [Lene Fredborg, 04-Jun-2019: Removed outdated link to http://www.microsoft.com/downloads/]

        On the other hand, "id" is a arbitrary user defined unique tag for custom controls like the separator used in the example above.  You can use practically anything you like but it must be unique for each control used.  A best practice is to stay consistent and use some sort of numerical sequence. 

- Save and close the CustomUI file.

- Place the template in your Word Startup folder and start Word.  Your ribbon should now appear modified as shown above.

 

 


The range of modification to the Ribbon UI using built-in controls and a few custom separators is practically endless.  With a valid, and yes lengthly, RibbonXML script you can create a custom tab containing almost all the classic menus and toolbars!

 

 


For the final example I will show you how add custom controls to the ribbon.  My most frequent customization of the menus and toolbars in the classic user interface was for docking macros or other shortcuts that a user could call from various Add-Ins that I have created.  

Lets creat the custom tab "My Tab" shown below.  It contains two custom groups "Macros" and "Shortcuts."  The Macro group contains a button control for displaying the VB Editor and a dropdown for calling several macros from a list.  The Shortcut group contains two toggle buttons.  One toggles the display of bookmarks while the other toggles the display of hidden text.  

Once again:

- Open Word.  Create and save a new macro enabled template.  For this example I created and saved a template named  "MVP FAQ Example 2"

- Close the template and close Word.

- Start the Office 2007 Custom UI Editor application and open the template file that you just created.

- Paste the following RibbonXML script in the CustomUI window.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<
customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="RibbonControl.Onload">
<
ribbon>
  <
tabs>
    <
tab id="CustomTab1" label="My Tab">
      <
group id="CustGrp1" label="Macros" >
        <
button id="Btn1" label="Show Visual Basic Editor" imageMso="VisualBasic"
                      
onAction="RibbonControl.MyBtnMacro" />
        <
dropDown id="DD1" label="Run Macro"
                                getItemCount="RibbonControl.GetItemCount"
                               
getItemLabel="RibbonControl.GetItemLabel"
                               
getSelectedItemIndex="RibbonControl.GetSelectedItemIndex"
                               
onAction="RibbonControl.MyDDMacro" />
      </
group>
      <
group id="CustGrp2" label="Shortcuts" >
        <
toggleButton id="TB1" size="normal"
                                    getImage
="RibbonControl.getImage"
                                   
getLabel="RibbonControl.getLabel"
                                   
onAction="RibbonControl.ToggleonAction"
                                  
 getPressed="RibbonControl.buttonPressed" />
        <
toggleButton id="TB2" size="normal"
                                  
getImage="RibbonControl.getImage"
                                   getLabel="RibbonControl.getLabel"
                                 
 onAction="RibbonControl.ToggleonAction"
                                 
 getPressed="RibbonControl.buttonPressed" />
      </
group>
    </
tab>
  </
tabs>
</
ribbon>
</
customUI>

There are several unique difference between the RibbonXML script used in the first two example and that used here.  Notice the complete absence of "idMso" and the exclusive use of "id" instead. 

:old:Reminder:  "idMso" is the fixed internal ID for built-in controls while "id" is a arbitrary user defined unique ID for custom controls. 

Also note the addition of the "onLoad="RibbonControl.Onload" in line 2 and the the instructions that I have indexed under the "id" attribute of the controls.  These are dynamic attributes or methods of the ribbon and its controls that use callbacks to interface and communicate with a VBA project in the template. 

When Word executes this RibbonXML scriptit really doesn't know (yet) how many items to put in the dropdown control or which label to apply.  It also doesn't know which image or label to to associate with the toggle buttons.  When the script is executed Word gets this information form data that you provide in a VBA project associated with the ribbonXML script through VBA callbacks.

- Save and close the Custom UI file.  

 - Now lets create the VBA project. 

:old:Warning: When you first open your template file in Word or click on My Tab you might think the world is coming to an end.  There will be several errors generated and displayed.  This is normal at this point because the ribbonXML script is looking for instructions from a VBA project doesn't exist yet.

- Start Word, open the template and open the VBA Editor.- Create two standard project modules "RibbonControl" and "Macros." 

:old:Note: The module names are arbitrary.  RibbonControl is used to match the callback specified in the RibbonXML script.  The project name and name specified in the script could be anything  you like.

- Paste the following code in the "RibbonControl" module"

Option Explicit
Public myRibbon As IRibbonUI

Sub Onload(ribbon As IRibbonUI)
'Creates a ribbon instance for use in this project
Set myRibbon = ribbon
End Sub

'Callback for DropDown GetItemCount
Sub GetItemCount(ByVal control As IRibbonControl, ByRef count)
'Tell the ribbon to show 4 items in the dropdown
count = 4
End Sub

'Callback for DropDown GetItemLabel
Sub GetItemLabel(ByVal control As IRibbonControl, Index As Integer, ByRef label)
'This procedure fires once for each item in the dropdown.  Index is received as 0, 1, 2, etc. and label is returned.
label = Choose(Index + 1, "Select from list", "Macro 1", "Macro 2", "Macro 3")
End Sub

'Callback DropDown GetSelectedIndex
Sub GetSelectedItemIndex(ByVal control As IRibbonControl, ByRef Index)
'This procedure is used to ensure the first item in the dropdown is selected when the control is displayed
Select Case control.id
  Case Is = "DD1"
    Index = 0
  Case Else
   
'Do nothing
End Select
End Sub

'Callback for DropDown onAction
Sub myDDMacro(ByVal control As IRibbonControl, selectedID As String,  selectedIndex As Integer)
Select Case selectedIndex
  Case 0
  
 'Do nothing
  Case 1
    Macros.Macro1
  Case 2
    Macros.Macro2
  Case 3
    Macros.Macro3
End Select
'Force the ribbon to restore the control to its original state
myRibbon.InvalidateControl control.id
End Sub

'Callback for Button onAction
Sub MyBtnMacro(ByVal control As IRibbonControl)
Select Case control.id
  Case Is = "Btn1"
    Macros.ShowEditor
  Case Else
  
 'Do nothing
End Select
End Sub

'Callback for Toogle onAction
Sub ToggleonAction(control As IRibbonControl, pressed As Boolean)
Select Case control.id
  Case Is = "TB1"
    ActiveWindow.View.ShowBookmarks = Not ActiveWindow.View.ShowBookmarks
  Case Is = "TB2"
   
'Note: "pressed" represents the toggle state. So we could use this instead.
    If pressed Then
      ActiveWindow.View.ShowHiddenText = False
    Else
      ActiveWindow.View.ShowHiddenText = True
    End If
    If Not ActiveWindow.View.ShowHiddenText Then
      ActiveWindow.View.ShowAll = False
    End If
End Select
'Force the ribbon to redefine the control wiht correct image and label
myRibbon.InvalidateControl (control.id)
End Sub

'Callback for togglebutton getLabel
Sub getLabel(control As IRibbonControl, ByRef returnedVal)
Select Case control.id
  Case Is = "TB1"
    If Not ActiveWindow.View.ShowBookmarks Then
      returnedVal = "Show Bookmarks"
    Else
      returnedVal = "Hide Bookmarks"

    End If
  Case Is = "TB2"
    If Not ActiveWindow.View.ShowHiddenText Then
      returnedVal = "Show Text"
    Else
      returnedVal = "Hide Text"
    End If
End Select
End Sub

'Callback for togglebutton getImage
Sub GetImage(control As IRibbonControl, ByRef returnedVal)
Select Case control.id
  Case Is = "TB1"
    If ActiveWindow.View.ShowBookmarks Then
       returnedVal = "_3DTiltRightClassic" 
'The idMso of a built-in control
    Else
      returnedVal = "_3DTiltLeftClassic" 
'The idMso of a built-in control
    End If
  Case Is = "TB2"
    If ActiveWindow.View.ShowHiddenText Then
      returnedVal = "WebControlHidden"
'The idMso of a built-in control
    Else
      returnedVal = "SlideShowInAWindow"
'The idMso of a built-in control
    End If
End Select
End Sub

'Callback for togglebutton getPressed
Sub buttonPressed(control As IRibbonControl, ByRef toggleState)
'toggleState (i.e., true or false) determines how the 'toggle appears on the ribbon (i.e., flusn or sunken).
Select Case control.id
  Case Is = "TB1"
    If Not ActiveWindow.View.ShowBookmarks Then
      toggleState = True
    Else
      toggleState = False
    End If
  Case Is = "TB2"
    If Not ActiveWindow.View.ShowHiddenText Then
      toggleState = True
    Else
    toggleState = False
    End If
End Select
End Sub

:old:Tip: Notice the  Select Case statements in the callback procedures.  You can use the same callback procedures and appropriate Case statements to process multiple controls.

  - Paste the following code in the "Macros" module:

Option Explicit

Sub ShowEditor()
ShowVisualBasicEditor = True
End Sub

 Sub Macro1()
 MsgBox "Macro 1 running"
'Replace this with whatever code you would wish to run.
 End Sub

 Sub Macro2()
 MsgBox "Macro 2 running"
'Replace this with whatever code you would wish to run.
 End Sub

 Sub Macro3()
 MsgBox "Macro 3 running"
'Replace this with whatever code you would wish to run.
 End Sub

 - Save and close the template

 - Open Word.  Your ribbon should now appear modified as shown above.  If you click on one of the macros in the list it will call that procedure from your VBA project.

 

 


I realize that the information and examples that are presented in this FAQ page won't make you an expert.  I am no expert either, but I am excited about learning more about Ribbon customization and I hope that you are too.   I have created several AddIns that use ribbon customization and posted them on my personal website.  One in particular that contains some advance Ribbon customization techniques is: Table Cell Data (Word 2007 Version)

 

Just remember that ribbon customization doesn't take rocket science!! 

 

   1.  All of the various Ribbon controls and their attributes are described in the technicals articles referenced above.

   2.  You can determine the idMso of most of the built-in commands using the Office Button>Word Options>Customize and scrolling your mouse over the built-in in command.  The idMso appears in screen tip in parenthesis e.g., Popular Commands | File (FileSave).  A complete list can be download from Microsoft: List of Control IDs [Lene Fredborg, 04-Jun-2019: Removed outdated link to http://www.microsoft.com/downloads/]

   3.  The schema used to validate the XML script in the Custom UI Editor can be downloaded from Microsoft:
CustomUI Schema [Lene Fredborg, 04-Jun-2019: Removed outdated link to http://www.microsoft.com/downloads/]