Summary: Learn how to customize the 2007 Office Fluent user interface. Also learn how new features in Microsoft Visual Studio 2005 Tools for the 2007 Microsoft Office System support RAD development of Ribbon customizations. (40 printed pages)
Frank Rice, Microsoft Corporation
Ken Getz, MCW Technologies, LLC
Published: May 2006
Updated: October 2006
Applies to: Microsoft Office Access 2007, Microsoft Office Excel 2007, Microsoft Office Outlook 2007, Microsoft Office PowerPoint 2007, Microsoft Office Word 2007, Microsoft Visual Studio 2005 Tools for the 2007 Microsoft Office System, Microsoft Visual Studio 2005
Contents
- An Improved User Interface
- New Ways to Enhance the User’s Experience
- What About Existing Solutions?
- Customizing the Fluent UI for Most Office Applications
- Using Callbacks
- Two Ways to Customize the Fluent UI
- Adding Document-Based Add-ins to the Fluent UI
- UI Customization in Access 2007
- Creating an Access Application-Level Custom Ribbon
- Loading Customizations at Run Time
- Ribbon Customization Scenarios for Other Applications
- Using COM Add-ins to Modify the Fluent UI
- Working with Existing Command-Bar Add-Ins
- Dynamically Updating the Fluent UI
- Loading Images
- Conclusion
- Additional Resources
An Improved User Interface
Many of the applications in the 2007 Microsoft Office system have a new look. The new Microsoft Office Fluent user interface (UI) replaces the current system of layered menus, toolbars, and task panes with a simpler system optimized for efficiency and discoverability. The new Fluent UI has improved context menus, Enhanced ScreenTips, a Mini toolbar, and keyboard shortcuts that help to improve user efficiency and productivity.
![]() |
---|
The Fluent UI is implemented in several applications in the 2007 Microsoft Office release, including Microsoft Office Access 2007, Microsoft Office Excel 2007, Microsoft Office PowerPoint 2007, and Microsoft Office Word 2007. The Ribbon is also available in Microsoft Office Outlook 2007 while you edit an Outlook item. You can customize the Fluent UI through a combination of XML markup and any Microsoft .NET Framework–based language that is supported in Microsoft Visual Studio. You can also customize the Fluent UI by using Microsoft Visual Basic for Applications (VBA), Microsoft Visual C++, and Microsoft Visual Basic 6.0. |
New Ways to Enhance the User’s Experience
Developers have taken advantage of the tools and programming structures in earlier versions of Office to extend the Fluent UI in creative ways. For example, the command bars object model enabled developers to build rich solutions in their custom Office applications. Continuing in that tradition, UI extensibility introduces an innovative model that you can use to enhance the user experience. You use extensible markup language (XML) and on
Figure 1. The Fluent UI in applications in the 2007 Office release
Using XML markup files to customize the Fluent UI greatly reduces the need for complex add-ins based on the command bars object model. However, add-ins written for previous versions of Office will continue to work in the Fluent UI with little or no modification.
What About Existing Solutions?
In previous versions of Office, developers used the command bars object model to build the Visual Basic co
Customizing the Fluent UI for Most Office Applications
You can create a custom application-level Fluent UI in Word 2007, in Excel 2007, or in PowerPoint 2007 in the following ways:
- By using COM add-ins in managed or unmanaged co
de - By using application-specific add-ins, such as .ppam and .xlam files
- By using templates (.dotm files) in Word 2007
![]() |
---|
Access 2007 and Outlook 2007 implement Ribbon customizations in slightly different ways than the other Office applications do. |
In a typical scenario, co
Document-level customizations use the same XML markup and an Office Open XML Formats file with on
Using Callbacks
You specify callbacks to update properties and perform actions from your Fluent UI at run time. For example, to specify an act
This markup tells Office to call the MyButtonOnAction method when the button is clicked. The MyButtonOnAction method has a specific signature depending on your choice of languages; here is an example:
public void MyButtonOnAction (IRibbonControl control) { if (control.Id == "myButton") { System.Windows.Forms.MessageBox.Show("Button clicked!"); } }
![]() |
---|
Depending on how you create your customization, you may need to add a reference to the System.Windows.Forms assembly to call the MessageBox.Show method. |
The MyButtonOnAction procedure must be declared as public. The control parameter carries the unique id and tag properties of the control, which enables you to use the same callback procedure for multiple controls.
![]() |
---|
All attributes in the Ribbon XML customization markup use the camel-casing convention, which capitalizes the first character of each word except the first word—examples include on |
Two Ways to Customize the Fluent UI
Applications that support the Ribbon (except Access 2007, as described Creating an Access Application-Level Custom Ribbon) provide two ways to customize the Fluent UI by using XML markup: by using Office Open XML Formats files that contain XML markup, or by using COM add-ins that contain XML markup. (In the case of Outlook, on
All controls in RibbonX markup must include on
Table 1. One of these identifiers must be used with all controls
Identifier | Description |
---|---|
id |
Specifies a unique identifier for the control. Used with custom controls. This identifier is passed as a property on an IRibbonControl to callback functions. |
idMso |
Specifies the identifier of a built-in control. |
idQ |
Specifies a qualified identifier, prefixed with a namespace abbreviation, as in the following example.
|
![]() |
---|
The example uses the namespace x so that two different add-ins can add to the same custom group—they just need to refer to that custom group by its qualified name. |
General Format of XML Markup Files
You can use XML markup to customize the Fluent UI. The following example shows the general format of an XML markup file that customizes the Fluent UI in Word 2007. Examples in the following sections use this markup.
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"> <ribbon> <tabs> <tab idMso="TabHome"> <group idMso="GroupFont" visible="false" /> </tab> <tab label="My Tab"> <group label="Sample Group"> <toggleButton size="large" label="Large Toggle Button" getPressed="ThisDocument.MyToggleMacro" /> <checkBox label="A CheckBox" screentip="This is a check box" /> <editBox getText="ThisDocument.MyTextMacro" label="My EditBox" /> <comboBox label="My ComboBox" > <item label="33455" /> <item label="81611" /> <item label="31561" /> </comboBox> <dialogBoxLauncher> <button screentip="My Launcher" /> </dialogBoxLauncher> </group> <group label="My Group" > <button label="My Large Button" size="large" /> <button label="My Normal Button" size="normal" /> </group > </tab> </tabs> </ribbon> </customUI>
This XML markup results in a modified Fluent UI, as the following figure shows.
Figure 2. Sample of Fluent UI customization in Word
This sample makes the following changes to the Fluent UI in Word 2007, in the order shown:
- The sample declares the default namespace for the XML markup.
- The sample hides the built-in GroupFont group that is located on the built-in Home tab.
- The sample adds a new CustomTab tab to the right of the last built-in tab, with the label My Tab.
Note:
Use the id identifier attribute to create a custom item, such as a custom tab. Use the idMso identifier attribute to refer to a built-in item, such as the TabHome tab. - The sample adds a new SampleGroup group to the My Tab tab.
- The sample adds a large-sized ToogleButton1 button to the My Group group. The markup specifies on
Act ion and getPressed callbacks. - The sample adds a CheckBox1 check box to the My Group group with a custom screentip. It also specifies an on
Act ion callback. - The sample adds an EditBox1 edit box to the My Group group and specifies an on
Change callback. - The sample adds a Combo1 combo box to the My Group group with three items and specifies an on
Change callback. - The sample adds a Launcher1 launcher to the My Group group with the on
Act ion callback set.A launcher normally displays a custom dialog box that offers more options to the user.
- The sample adds a new My Group group to the custom tab.
- The sample adds a large-sized Button1 button to the My Group group and specifies getText and on
Act ion callbacks. - The sample adds a normal-sized Button2 button to the My Group group and specifies an on
Act ion callback.
The easiest way to create RibbonX markup is to use a validating XML editor. Microsoft Visual Studio 2005 provides such an editor that you can use, if you can provide the necessary schema (XSD) file. In this case, you need a current copy of customUI.xsd, which is available in several places. For example, when you install Microsoft Visual Studio 2005 Tools for the 2007 Microsoft Office System (also known as Visual Studio 2005 Tools for Office Second Edition), it adds the schema to the Visual Studio schema catalog, so the schema is available by default in a Visual Studio project. You can also find the schema at the 2007 Office System: XML Schema Reference Web site. In Visual Studio, create a new XML file, and in the Properties window, set the Schemas property to include the customUI.xsd file (or enter the schema reference in the co
Customizing the Fluent UI by Using Office Open XML Formats Files
At the document level, the process for customizing the Fluent UI by using XML markup involves the following steps. For more information, see Adding Document-Based Add-ins to the Fluent UI later in this article. You can follow these steps, using the XML markup described in the previous section.
![]() |
---|
Although it is useful to know what is going on within the Office Open XML Formats structure, you may be able to bypass these steps. You can take advantage of the Custom Fluent UI Editor, available at OpenXMLDeveloper.org. This tool enables you to open a document, insert custom UI, and then save the document with the RibbonX markup in place. It performs for you the steps listed in this example. It also enables you to add custom icons to the customUI folder, and makes it easy to refer to these icons. You can download the Custom UI Editor from the OpenXMLDeveloper.org Custom UI Editor Tool Web page. |
To customize the Fluent UI by using Office Open XML Formats files
- Create a folder on your desktop named customUI.
- Create the customization file in any text editor by writing XML markup that adds new components to the Fluent UI, modifies existing components, or hides components. You can use the XML markup from the previous example, to test the beha
vior. Save the file as customUI.xml (or any other name) in the folder you just created. - Validate the XML markup against your custom Fluent UI schema (optional).
- Create a document in the Office application, and then save it as an Office Open XML Formats file with on
e of these extensions: .docx, .docm, .xlsx, .xlsm, .pptm, or .pptx. File name extensions for files that contain macros have an “m” suffix. These files can contain procedures that can be called by RibbonX commands and controls.
Warning:
You must save the document in macro-enabled format if you want to add co de that reacts when the user interacts with the Ribbon customization. Documents with this functionality include the .docm, .xlsm, and .pptm formats. For all the examples in this article that include Microsoft Visual Basic for Applications (VBA) co de, you must save the host document as on e of these formats.
<Relationship Type="http://schemas.microsoft.com/office/2006/ relationships/ui/extensibility" Target="/customUI/customUI.xml" />
When you open the file in the Office application, the UI appears with your customizations. Depending on your application settings, if you use the markup from the previous section in this example, you might receive several warning messages as you open the document. Because you have not supplied the co
Adding Document-Based Add-ins to the Fluent UI
The following steps outline the basic process for creating a document that contains a simple custom UI in Excel 2007 that can call a custom macro:
- Create a macro-enabled Excel workbook with on
e macro. - Create a file to customize the Fluent UI by adding on
e tab, on e group, and on e button. - Create a procedure in VBA that the Fluent UI calls, in response to the button being clicked.
- Specify the on
Act ion callback attribute in the button’s markup, so that it calls the macro you created in the document. - Modify the contents of the macro-enabled document container so that it contains the file that customizes the Fluent UI.
- Save the macro-enabled file, and then open it in Excel 2007.
![]() |
---|
You can follow these same basic steps when creating a macro-enabled Word or PowerPoint document. |
To create an Excel workbook that is macro-enabled
- Start Excel 2007.
- Click the Developer tab, and then click Visual Basic.
Note:
If you do not see the Developer tab, you must identify yourself as a developer. To do this in your application, click the Microsoft Office Button, click Application Options, click Popular, and then select Show Developer Tab in the Ribbon. This is a global setting that identifies you as a developer in all Office applications that implement the Fluent UI. - In the Visual Basic Editor, double-click ThisWorkbook to open the Co
de window. - Type the following VBA function, and then click the Excel icon in the left corner of the toolbar to return to Excel.
- Save the document as a macro-enabled workbook with the file name extension .xlsm.
Note:
If you save the document as a standard .xlsx document, you will not be able to run the macro co de. When you save the document, you must explicitly select the Save As menu option, and then select Excel Macro-Enabled Workbook (*.xlsm). - Exit Excel.
To create the file that contains the XML markup to modify the Fluent UI
- Create a folder on your desktop named customUI.
- Create a new text file, add the following XML, and then save the file as customUI.XML in the customUI folder on your desktop.
To modify files contained in the macro-enabled file container
- In Windows Explorer, find the macro-enabled file you created. Rename the file by adding the .zip extension.
- In Windows Explorer, double-click the file to open it.
- Add the customization file to the container by dragging the customUI folder from the desktop to the compressed folder and clicking the Add button when prompted.
- Drag the _rels folder to the desktop.
- Open the new folder, and then open the .rels file in a text editor.
- Add the following text between the last <Relationship> element and the </Relationships> element, and then save and close the file.
<Relationship Type="http://schemas.microsoft.com/office/2006/relationships/ui/extensibility" Target="customUI/customUI.xml" />
- Drag the .rels file from the desktop to the _rels folder in the compressed folder, replacing the existing .rels file.
- Remove the .zip extension from the container file name.
- Open the macro-enabled file in Excel 2007. The custom UI replaces the built-in Fluent UI.
Note:
Depending on your security settings, you might see a security warning telling you that macros have been disabled. If you do, click the Options button that appears next to the warning, select Enable this content, and then click OK. - Click Large Button. Clicking the button triggers the on
Act ion callback, which calls the macro in the workbook, which displays the “Hello World” message.
Customizing the Fluent UI with COM Add-Ins
Customizations at the application level result in a modified Fluent UI that appears in the application regardless of which document is open. Generally, COM add-ins make these modifications. You generally have two options for creating COM add-ins by using managed co
To customize the Fluent UI by using COM add-ins
- Create a COM add-in project.
The add-in you create must implement the Extensibility.IDTExtensibility2 interface and the IRibbonExtensibility interface (found in the Microsoft.Office.Core namespace).
- Build the add-in and Setup project and then install the project.
- Start the Office application.
When the add-in loads, the IDTExtensibility2::On
Next, Office calls either the QueryInterface method (for unmanaged add-ins) or the QueryService method (for managed add-ins), which determines whether the add-in implements the IRibbonExtensibility interface. If it does, Office calls the IRibbonExtensibility::GetCustomUI method, which returns the XML markup (from an XML customization file or from XML markup embedded in the procedure), and then Office loads the customized Fluent UI into the application. Finally, the customized UI is ready for the user.
![]() |
---|
Because of the internal architecture of the Ribbon callback mechanism, it is imp |
Each control specified in the XML markup exposes its functionality by calls to callback procedures. For example, the XML markup for a button control can specify an on
UI Customization in Access 2007
RibbonX customizations in Access 2007 share some of the same options that the other Office applications have, but with some imp
Access does provide flexibility in customizing the Fluent UI. For example, customization markup can be stored in a table, embedded in a VBA procedure, stored in another Access database, or linked to from an Excel worksheet. You can also specify a custom UI for the application as a whole or for specific forms and reports.
The following scenarios can give you an idea of how to customize the Access UI.
![]() |
---|
Because these walkthroughs involve changes to the database, you might want to perform these steps in a non-production database, perhaps by using a backup copy of a sample database. |
Customizing the Fluent UI in Access
When customizing the Access UI, you have two choices: You can store your customizations in a special table and have Access automatically load the markup for you, or you can store the customizations in a location of your choosing and load the markup manually by calling the Application.LoadCustomUI method.
If you choose to have Access load the customizations for you, you need to store them in a table named USysRibbons. The table should have at least two columns: a 255-character Text column named RibbonName, and a Memo column named RibbonXML. You place the Ribbon name in the RibbonName column, and the Ribbon markup in the RibbonXML column. After you close and re-open the database, you can select the default Ribbon to use in the Access Properties dialog box. You can select a Ribbon to appear when any form or report is selected as a property of the form or report.
If you decide to use a more dynamic technique, you can call the LoadCustomUI method, which loads Ribbon customizations whether the XML content is stored in a table or not. After you have loaded the customizations by calling LoadCustomUI, you can programmatically assign the named customization at run time.
![]() |
---|
Customizations that you load by using the LoadCustomUI method are available on |
The signature for the LoadCustomUI method is as follows.
expr
expr
CustomUIName is the name of the Custom Ribbon ID to be associated with this markup.
CustomUIXML contains the XML customization markup.
There is an example of using the LoadCustomUI method Loading Customizations at Run Time.
The following procedure describes, in a generalized manner, how to add application-level customizations in Access. A later section includes a complete walkthrough.
To apply a customized application-level Ribbon at design time
- Create a table named USysRibbons with columns as described earlier. Add rows for each different Ribbon you want to make available.
- Close and then reload the database.
- Click the Microsoft Office Button, and then click Access Options.
- Click the Current Database option and then, in the Ribbon and Toolbar Options section, click the Ribbon Name drop-down list and click on
e of the Ribbons.
To remove an existing customization (so that your database uses the default Fluent UI), delete the existing Ribbon name from the Ribbon Name list, and leave an empty value for the name of the Ribbon.
The following procedure describes, in a generalized manner, how to add form-level customizations or report-level customizations in Access.
To assign a specific custom Ribbon to a form or report
- Follow the process described previously to make the customized Ribbon available to the application, by adding the USysRibbons table.
- Open the form or report in Design view.
- On the Design tab, click Property Sheet.
- In the Property window, on the Other tab, click the Ribbon Name drop-down list, and then click on
e of the Ribbons. - Save, close, and then re-open the form or report. The UI you selected is displayed.
Note:
The tabs displayed in the Fluent UI are additive. That is, unless you specifically hide the tabs or set the Start from Scratch attribute to True, the tabs displayed by a form or report’s UI appear in addition to the existing tabs.
To explore this process further, work through the following examples.
The first part of the example sets an option that reports any errors that exist when you load custom UI (although you are performing these steps in Access, you can perform similar steps in other applications).
Creating an Access Application-Level Custom Ribbon
To create an Access application-level custom ribbon
- Start Access. Open an existing database, or create a new database.
- Click the Microsoft Office Button, click Access Options, and then click the Advanced tab.
- In the General section, select the option Show add-in user interface errors (this option might be in a different location, in different applications).
- Click OK to close the Access Options dialog box.
Next, create a table that contains your customization XML markup.
- With a database open in Access, right-click the Navigation pane. Point to Navigation Options, and then click Show System Objects. (You cannot view the USysRibbons table in the Navigation pane unless this option is set.) Click OK to dismiss the dialog box. The Access system tables appear in the Navigation pane.
- On the Create tab, click Table Design.
- Add the following fields to the table.
Table 2. USysRibbons table field definitions
Field Name Type ID
AutoNumber
RibbonName
Text
RibbonXml
Memo
- Select the ID field. On the Design tab, select Primary Key.
- Click the Microsoft Office Button, and then click Save. Name the new table USysRibbons.
- Right-click the USysRibbons tab, and then click Datasheet View.
- Add the following da
ta to the fields you created.
Table 3. USysRibbons table da
ta Field Name Value ID
(AutoNumber)
RibbonName
HideData
RibbonXml
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"> <ribbon startFromScratch="false"> <tabs> <tab idMso="TabCreate" visible="false" /> <tab label="A Custom Tab" visible="true"> <group label="A Custom Group"> <control idMso="Paste" label="Built-in Paste" enabled="true"/> </group> </tab> </tabs> </ribbon> </customUI>
This markup sets the startfromScratch attribute to False, and then hides the built-in Create tab. Next, it creates a custom tab and a custom group, and adds the built-in Paste control to the group.
- Close the table.
- Close and then re-open the database.
- Click the Microsoft Office Button, and then click Access Options.
- Click the Current Database tab, and scroll down until you find the Ribbon and Toolbar Options section.
- In the Ribbon Name drop-down list, select HideData. Click OK to dismiss the dialog box.
- Close and re-open the database.
The Edit group is no longer displayed, and the Fluent UI includes the A Custom Tab tab, which contains the A Custom Group group with the Built-in Paste button.
Figure 3. The Access application-level UI
- To clean up, repeat the previous few steps to display the Access Options dialog box. Delete the contents of the Ribbon Name option, so that Access displays its default Fluent UI after you close and re-open the database.
Note:
You can also use a Ribbon from the USysRibbons table to supply the UI for a specific form or report. To do this, open the form or report in Design or Layout mode, and set the form’s RibbonName property to the name of the Ribbon you want to use. You must select the form itself, rather than any control or section on the form, before you can set this property.
Loading Customizations at Run Time
If you want to load static customizations at run time, you can store those customizations in the USysRibbons table, and set a form or report’s RibbonName property as necessary. But, if you need to create dynamic customizations, call the Application.LoadCustomUI method. The following example creates a Ribbon customization that displays a button for each form in the application, and handles the on
To create a dynamic Ribbon customization
- Load the database that you worked with in the previous section into Access 2007. If your database does not already include more than on
e form, create a few forms, and add a control or two to each form. - On the Create tab, in the Other group, click the drop-down list of the Macro button, and then click Module.
- In the Visual Basic Editor, on the View menu, click Properties Window.
- In the Properties window, in the Name property box, change the name of the module to RibbonLoader.
- In the co
de window, insert the following co de. Even though this method does not return a value, it must be a function—otherwise, you cannot call it from an Access macro. Function CreateFormButtons() Dim xml As String xml = _ "<customUI xmlns=""http://schemas.microsoft.com/" & _ "office/2006/01/customui"">" & vbCrLf & _ " <ribbon startFromScratch=""false"">" & vbCrLf & _ " <tabs>" & vbCrLf & _ " <tab >"DemoTab"" label=""LoadCustomUI Demo"">" & _ vbCrLf & _ " <group >"loadFormsGroup"" label=""Load Forms"">" & _ vbCrLf & _ "{0}" & vbCrLf & _ " </group>" & vbCrLf & _ " </tab>" & vbCrLf & _ " </tabs>" & vbCrLf & _ " </ribbon>" & vbCrLf & _ "</customUI>" Dim template As String template = "<button >"load{0}Button"" " & _ "label=""Load {0}"" >"HandleOnAction"" " & _ "tag=""{0}""/>" & vbCrLf Dim formContent As String Dim frm As AccessObject For Each frm In CurrentProject.AllForms formContent = formContent & _ Replace(template, "{0}", frm.Name) Next frm xml = Replace(xml, "{0}", formContent) Debug.Print xml On Error Resume Next ' If you call this co
de from the AutoExec macro, ‘ the on ly way it can fail is if you have a ‘ customization with the same name in the ‘ USysRibbons table. Application.LoadCustomUI “FormNames”, xml End Function
When you run the co
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"> <ribbon startFromScratch="false"> <tabs> <tab label="LoadCustomUI Demo"> <group label="Load Forms"> <button label="Load Form2" tag="Form2"/> <button label="Load Form1" tag="Form1"/> </group> </tab> </tabs> </ribbon> </customUI>
This markup creates a new LoadCustomUI Demo tab that contains a Load Forms group. Within the group, the Ribbon displays a button for each form in the application (Form1 and Form2), and indicates that each button should call the HandleOnAction callback procedure when clicked. In addition, the markup sets the Tag attribute for each button so that it contains the name of the Access form that your co
Public Sub HandleOnAction(control As IRibbonControl) ' Load the specified form, and set its ' RibbonName property so that it displays ' the custom UI. DoCmd.OpenForm control.Tag Forms(control.Tag).RibbonName = "FormNames" End Sub
The startup form opens, along with a custom tab that contains a group that displays a button for each form in your application. Click any of the buttons: Access opens the corresponding form, maintaining the same custom UI.
In addition to the described techniques, you can add Ribbon customizations to Access by using a COM add-in. COM add-ins provide the benefit of adding custom RibbonX functionality as a package without the need to add VBA co
![]() |
---|
Although you can use the Visual Studio 2005 Shared Add-In template to create a COM add-in for Access, you cannot use Visual Studio 2005 Tools for Office Second Edition to create COM add-ins for Access. Access is not on |