In order for XML documents to be able to use elements and attributes that have the
same name but come from different sources, there must be a way to differentiate
between different sources of markup elements. In XML, a namespace is a collection of names, identi-
fied by a URL reference, that are used as element types and attribute names in XML documents.
The XML code starts with specifying the namespace as http://schemas.microsoft.com/
office/2006/01/customui. This is the only XML namespace used for Office 2007 Ribbons.
Next, the Ribbon’s startFromScratchattribute is set to “false” (for VBA programmers, note that
in XML code, the syntax is “false”, with the quotes, not just False, as in VBA code). This setting
means that you are modifying the standard toolbar, as opposed to creating a Ribbon from scratch.
The next sections show how to customize the Ribbon in various ways.
Adding a New Tab, Group, and Controls to the Ribbon ................................
To create a custom tab for the Ribbon, under the <tabs> section of the XML code, add a tab line
and set its id and label attributes as desired. The idattribute is a unique identifier for a custom
Ribbon control that can be used elsewhere in XML code to reference the tab, and the labelattrib-
ute is set with the caption text to display on the tab. Set the tab’s visible attribute to “true” to dis-
play it. Next, create one or more groups for the custom tab, setting their id and label attributes
with the names and captions of the groups. Finally, add one or more controls to a group (or several
groups) on the tab; for the sample XML code I created two buttons, each of which runs a callback
function.
See Table 15.1 for a list of the most commonly used elements for creating tabs, groups,
and controls on the Ribbon.
Controls have (minimally) id and label attributes, and also an enabledattribute (usually set to
“true”). They typically display an image, which is usually set with imageMsoargument, using a
value corresponding to the standard Ribbon button that has the image you want to display.
You can’t remove a control from a standard Ribbon group, or add a control to a stan-
dard group; see the sidebar earlier in this chapter for Patrick Schmid’s illuminating com-
mentary on this issue. For Microsoft’s justification of this policy, see the Developer Overview of the
User Interface for the 2007 Microsoft Office System article (http://msdn2.microsoft.com/
en-us/library/aa338198.aspx). It boils down to something like “We made the Ribbon perfect,
so users don’t need to customize it.” Needless to say, I (and many other developers and power users)
disagree. The Ribbon is indeed a great improvement over command bars and menus, but I would really
like to be able to drag a button I need to a standard group, or remove one that I never use.
To use the Form image on a custom control, use “CreateForm”as the imageMso argument value
when defining the button in XML code.
The control’s size attribute has only two selections: “large” and “normal”. Lastly, for a command
button, set the onAction attribute with the name of a function to run when the button is clicked.
NOTENOTE
CROCROSSSS-REF-REF
NOTENOTE
Customizing the Ribbon with XML in Access Databases and Add-ins 15