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.

^ If you just want a quick way to run some of your own macros, the Office 2007 programs enable you to add macros to the Quick Access toolbar; see "Creating a Quick Access Toolbar Button for a Recorded Macro," p. 11.

I just told you that the 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.

This book is, by design, short on theory and long of practicality. However, before getting to the nuts and bolts of extending the Ribbon, you need to understand just a bit of background about the Office XML file formats, not least because they are quite unlike any file format you've probably seen.

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 automagi-cally converts to a valid zip container format. And if you open that container, you see the folders and files that it contains. For example, I took this chapter's example file— Chapterl3.docm—added the .zip extension, and then opened it, as shown in Figure 13.1.

As you'll see, much of the work you perform in this chapter involves changing the extensions of ° Office files to .zipand 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.

Figure 13.1

Rename an Office 2007 file with the .zip extension and it becomes a zip package that contains other folders and files.

snfsiËS

t PaulMtFWhH t Doiunwnts ► Proje

rts » Lhjpttrli » Lhipttrlii«mjip •

*\*t\\ S»«*

Ml

*tt«4 Siii PEUWOU! _

O Ootuminh £ FKtues IP' Music

M Rtitrtlv Chxnqcd f? jtir:hti

Ji PuWfc

I dwPiopt J. «¡-.J [Cnntcnt.TyRci]anl

MtfoWiT fib fold* N*F«M« XMl Document

1KB No

i 1» 7ÎN 12/

| 4 ttrrvi

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 chapter 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.

0 0

Post a comment