Overview of the Ribbon User Interface
Office Developer Reference |
Overview of the Ribbon User Interface |
![]() |
---|
The use of CommandBars in some Microsoft Office applications has been superseded by the new Ribbon user interface. For more information, search help for the keyword "Ribbon." |
The Ribbon user interface (UI) feature replaces the current system of layered menus, toolbars, and task panes with a simpler system of interfaces optimized for efficiency and discoverability. The new UI has improved context menus, screentips, a Mini toolbar, and keyboard shortcuts that improve user efficiency and productivity. Ribbon Extensibility (or RibbonX) introduces an innovative model that developers can use to enhance the user experience. You use extensible markup language (XML) and one of several conventional programming languages to manipulate the components that make up the Ribbon UI. Because XML is plain text, you can create customization files in any text editor, or you can use your favorite XML editor. You can also reuse custom Ribbon UI files with a minimum of adjustments because each application uses the same programming model. For example, you can reuse the custom UI files you create in Microsoft Office Microsoft Word, Microsoft Office Excel® 2007, Microsoft Office Access 2007, or Microsoft Office PowerPoint® 2007.
Using XML markup files to customize the UI greatly reduces the need for complex add-ins based on the CommandBars object model. However, add-ins written in previous versions of Office continue to work in the Ribbon UI with little or no modification. You can create a custom application-level Ribbon UI in Microsoft Word, in Excel 2007, or PowerPoint 2007 in the following ways:
- Using COM add-ins in managed or unmanaged code
- Using application-specific add-ins, such as .ppam and .xlam files
- Using templates (.dotm files) in Microsoft Word
In a typical scenario, code in the COM add-in contains procedures that return XML markup either from an external customization file or from XML contained in the code itself. When the application starts, the add-in loads and executes the code that returns the XML markup. Microsoft Office validates the XML markup against an XSD schema, and then loads it into memory and applies it to the UI. The modified Ribbon UI is then displayed. Menu items and controls use callback procedures to execute code in the add-in. Document-level customizations use the same XML markup and an Open XML Formats file with one of these extensions: docx, .docm, .xlsx, .xlsm, .pptx, .or pptm. In this scenario, you create a customization file that contains the XML markup and save it to a folder. You then modify the parts in the Open XML Formats container to point to the customization file. When you open the document in the Office application, the customization file loads into memory and is applied to the Ribbon UI. The commands and controls then call code contained in the document to provide their functionality.In previous versions of Microsoft Office, developers used the CommandBars object model to build the Microsoft Visual Basic® code that modified the UI. In Office 2007, this legacy code continues to work in most cases without modification. However, changes made to toolbars in Office 2003 now appear on an Add-Ins tab in the 2007 release of Microsoft Office Suites. The type of customization that appears depends on the original design of the add-in. For example, Office creates a Menu Commands group that contains items added to the previous menu structure (File menu, Insert menu, Tools menu, and so forth). It also creates a Toolbar Commands group that contains items added to the previous built-in toolbars (such as the Standard toolbar, Formatting toolbar, and Picture toolbar). In addition, custom toolbars added by an add-in or document appear in the Custom Toolbars group on the Add-Ins tab. With Ribbon Extensibility, you specify callbacks to update properties and perform actions from your UI at runtime. For example, consider the onAction callback method for a button. The RibbonX markup looks like: <button onAction="MyButtonOnAction" />
This markup tells Office to call the MyButtonOnAction function when the button is clicked. The MyButtonOnAction function has a specific signature depending upon your choice of languages; here is an example in Microsoft Visual C#®:
|
Customization at the application-level results in a modified Ribbon UI that appears in the application regardless of which document is open. Primarily, you create COM add-ins to make these modifications. To customize the Ribbon UI using COM add-ins:
- Create a COM add-in project. The add-in you create must implement the Extensibility.IDTExtensibility2 interface as with all COM add-in and the additional 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::OnConnection event is triggered which initializes the add-in, just as in previous versions of Office.
- Next, the QueryInterface method is called which determines if the IRibbonExtensibility interface is implemented.
- If so, the IRibbonExtensibility::GetCustomUI method is called which loads the XML markup (from the XML customization file or from XML markup embedded in the procedure) and then loads the customizations into the application.
- Finally, the customized UI is ready for the user.
- Create the customization file in any text editor by adding XML markup that adds new components to the Ribbon UI, modifies existing components, or hides components. Save the file as customUI.xml.
- Create a folder on your desktop named customUI and copy the customization file to the folder.
- Validate the XML markup with custom UI schema.
Note
This step is optional. - Create a document in the Office application, and then save it as an Open XML Formats file with one of these extensions: .docx, .docm, .xlsx, .xlsm, .pptm, or .pptx. Files containing macros have an m suffix. These files can contain procedures called by RibbonX commands and controls.
- Add a .zip extension to the document file name, and then open the file.
- Add the customization file to the container by dragging the folder to the file.
- Extract the .rels file to your desktop. A _rels folder containing the .rels file is copied to your desktop.
- Open the .rels file and add a line that creates a relationship between the document file and the customization file, and then save the file.
- Add the _rels folder back to the container, overwriting the existing file.
- Rename the file to its original name by removing the .zip extension. When you open the Office file, the Ribbon UI appears with your customization.
|
This sample makes the following changes to the Ribbon UI in Microsoft Word, in the order shown:
- First the sample declares the default namespace and a custom namespace.
- The sample then hides the built-in GroupFont group that is located on the built-in Home tab.
- The sample then adds a new CustomTab tab to the right of the last built-in tab. attribute to create a custom item, such as a custom tab. Use the attribute to refer to a built-in item, such as the TabHometab.
Note
Use the id= identifier idMso= identifier - The sample adds a new SampleGroup group to the My Tab tab.
- The sample adds a large-sized ToogleButton1 button to My Group. An onAction callback and GetPressed callback is also specified.
- The sample adds a CheckBox1 check box to My Group with a custom screentip. An onAction callback is also specified.
- The sample adds a EditBox1 edit box to My Group. An onChange callback is also specified.
- The sample adds a Combo1 combo box to My Group with three items. The combo box specifies an onChange callback that uses the text from each item.
- The sample adds a Launcher1 launcher to My Group with the onAction callback set. A launcher may also display a custom dialog box to offer more options to the user.
- The sample adds a new MyGroup group to the custom tab.
- The sample adds a large-sized Button1 button to MyGroup. An onAction callback is also specified.
- Finally, the sample adds a normal-sized Button1 button that is a normal-sized button to MyGroup. An onAction callback is also specified.
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="ribbonLoaded">
In C#: Write a callback in your Connect class:
|
The new UI in Office 2007 offers users a flexible way to work with Office applications. The Ribbon feature uses text-based, declarative XML markup that simplifies creating and customizing the Ribbon. With a few lines of XML, you can create just the right interface for the user. Because the XML markup is contained in a single file, modifying the interface as requirements change is much simpler. You can also improve user productivity by putting the commands where users can easily find them. Finally, the Ribbon adds consistency across applications, which reduces the time users spend learning each application.ofv