How to: Customize the Ribbon UI by using an Office Open XML Formats File
The Ribbon user interface (UI) in the 2007 release of Microsoft® Office suites offers users a flexible way to work with Office applications. Ribbon Extensibility (RibbonX) uses text-based, declarative XML markup that simplifies creating and customizing the Ribbon UI. This sample demonstrates how to add custom components to the Ribbon UI for a single document as opposed to application-level customizations. In the following steps, we add a custom tab, a custom group, and button to the existing Ribbon UI in Microsoft Office Word 2007. We also implement a callback procedure for the button that inserts a company name into the document.
- Create the customization file in any text editor and save the file with the name customUI.xml.
- Add the following XML markup to the file and then close and save the file:
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"> <ribbon> <tabs> <tab id="CustomTab" label="My Tab"> <group id="SampleGroup" label="Sample Group"> <button id="Button" label="Insert Company Name" size="large" onAction="ThisDocument.InsertCompanyName" /> </group > </tab> </tabs> </ribbon> </customUI>
Note This step is optional. Sub InsertCompanyName(ByVal control As IRibbonControl) ' Inserts the specified text at the beginning of a range or selection. Dim MyText As String Dim MyRange As Object Set MyRange = ActiveDocument.Range MyText = "Microsoft Corporation" ' Range Example: Inserts text at the beginning ' of the active document MyRange.InsertBefore (MyText) ' Selection Example: 'Selection.InsertBefore (MyText) End Sub
<Relationship Id="someID" Type="http://schemas.microsoft.com/office/2006/relationships/ui/extensibility" Target="customUI/customUI.xml" />
See Also