MS-Excel / General Formatting

Understanding Ribbon Extensibility

If you've used previous versions of Office to customize menus and toolbars, you'll no doubt be disappointed to learn that all your hard-won customization knowledge must now be discarded. Most unfortunately, Microsoft offers no direct method for customizing the Ribbon and its various tabs, groups, and buttons. Note that this does not mean that the Ribbon isn't customizable. It certainly is, but it's just that now the process is much more involved and requires quite a few more steps.

Ribbon is customizable, but to be accurate I should really say that the Ribbon is extensible. This makes sense (at least a little bit) when you understand that the Office 2007 applications are built around the Office Open XML Formats, where XML stands for eXtensible Markup Language. It's this use of XML throughout Office 2007 that enables you to extend the Ribbon with your own custom interface elements, including tabs, groups within tabs, and buttons within groups.

The first thing you need to know about the Office XML formats is that a given file (such as a Word .docx document or an Excel .xlsx workbook) isn't really a single file at all. Instead, it's a container-or package-that contains multiple folders and files. In fact, this package is actually a file that uses the standard zip (compressed) file format. When, say, a Word document uses the .docx extension, it appears to be just a single file that works just like any other Word document. However, if you rename the file with a .zip extension, it automagically converts to a valid zip container format. And if you open that container, you see the folders and files that it contains.

As you'll see, much of the work you perform in this tutorial involves changing the extensions of Office files to .zip and back again.To do this, you must configure Windows to display file extensions. Click Start, Control Panel, and then open the Folder Options icon. (In Vista's Control Panel, you might have to first click Appearance and Personalization.) Click the View tab and then click to deactivate the Hide Extensions For Known File Types check box. Click OK.

Each of the files in the container is called a part, and the parts are grouped roughly into three categories:

  • Built-in elements that are shared by all Office applications, including document properties, comments, hyperlinks, and objects such as charts, SmartArt, and shapes.
  • Built-in elements that are specific to each Office application, such as Word headers and footers, Excel worksheets, and PowerPoint slides.
  • User-defined content, including the document text and VBA elements added to the document project, including macros and user forms.

All this is tied together by a special XML file named .rels in the container's _rels folder. This document consists of several <Relationship> elements, each of which has the following general form:

<Relationship Id="ID" Type="relationshipType" Target="targetPart" />
ID
A string that names the relationship. This name must be unique within the .rels file.

relationshipType
The address of the XML schema that specifies the type of relationship.

targetPart
The path and file name within the package that points to the part governed by the relationship.

In a Word document, for example, the document text part is in the word/document.xml file within the container and the schema for this part is located here:

http://schemas.openxmlformats.org/officeDocument/2006/relationships/ officeDocument

Here then is the complete <Relationship> element for this part:

<Relationship Id="rId1"
	Type="http://schemas.openxmlformats.org/
	officeDocument/2006/relationships/officeDocument"
	Target="word/document.xml" />

The key point for the purposes of this tutorial is that, just as with any zip file, you can add files to an Office XML container. In particular, you can add an XML file that specifies your custom Ribbon configuration. The next time you load that Office document, the program parses your custom XML document and extends the Ribbon accordingly. The next section takes you through an example.

[Contents] [Next]