Step 2: Create a Text File and Add the Custom XML Markup
You're now ready to create the custom XML markup for the Ribbon tabs, groups, and controls you want to display. In the same folder that you're using to store the macro-enabled document or template, create a text document named (for example) MyRibbon.xml. Open the file in Notepad or some other text editor and then begin the XML markup as follows:
If you're working with Word's Normal template, you can open its folder by pressing Windows Logo+R, entering the following path in the Run dialog box, and then clicking OK:
%UserProfile%\appdata\Roaming\Microsoft\Templates
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"> <ribbon> <tabs> </tabs> </ribbon> </customUI>
Now add a tab (See "Creating a New Tab", later in this tutorial, for the details:
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"> <ribbon> <tabs> <tab id="CustomTab" label="My Tab"> </tab> </tabs> </ribbon> </customUI>
Now add a group (see "Creating a New Group," later in this tutorial):
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"> <ribbon> <tabs> <tab id="CustomTab" label="My Tab"> <group id="CustomGroup" label="My Group" > </group> </tab> </tabs> </ribbon> </customUI>
Finally, add the markup for a button (see "Creating Custom Controls," later in this tutorial):
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"> <ribbon> <tabs> <tab id="CustomTab" label="My Tab"> <group id="CustomGroup" label="My Group" > <button id="CustomButton1" imageMso="HappyFace" label="Hello World!" size="large" onAction="Module1.MyButton" /> </group> </tab> </tabs> </ribbon> </customUI>
Note, in particular, that the button's onAction parameter references the callback macro added to the document earlier (Module1.MyButton).
In this tutorial:
- Customizing the Office 2007 Ribbon
- Understanding Ribbon Extensibility
- Extending the Ribbon: An Example
- Step 1: Create a Macro-Enabled Office Document or Template
- Step 2: Create a Text File and Add the Custom XML Markup
- Step 3: Copy the Custom XML Markup File to the Document Package
- Step 4: Rename and Open the Document
- Hiding the Built-In Ribbon
- Creating Custom Tabs
- Customizing an Existing Tab
- Creating Custom Groups
- Customizing an Existing Group