Obtaining and using the Office Custom UI Editor

The official method for modifying the Ribbon has you changing the file extension, extracting the required files, making modifications in an editor, archiving the files again, and, finally, changing the file extension back every time you want to make any change at all. You can see this grueling and error-prone method at http://msdn2.microsoft.com/en-us/ library/ms40 6046.aspx. The better way to make changes is to rely on a utility named Office 2007 Custom UI Editor, or Custom UI Editor, for short(http://openxmldeveloper.org/articles/CustomUIeditor. aspx). The direct download link is at http://openxmldeveloper.org/ attachment/23 9.ashx.

Using the Custom UI Editor is easier than the difficult process that Microsoft suggests. All you do is open your document, template, or add-in, make the required Ribbon additions, and save the file. The next time you open the file in the Office application, it contains the updated Ribbon. Figure 12-3 shows a typical example of the Custom UI Editor in action.

Don't let the XML in this example scare you. As with every XML file, this one starts with an XML processing instruction. The root node, which contains everything else, is <customUI>. The child of interest for this example is <ribbon>, which contains all the Ribbon additions. You can use other child elements on complex setups, such as the <commands> element that lets you change an existing command to do something else.

Most Ribbon additions consist of three elements. First, you need a tab, which is the selection you choose to locate a particular Ribbon display. The default tabs have names such as Home and Insert. Second, you need a group to hold and organize various controls. For example, the Clipboard group on the Home tab organizes the Cut, Copy, Paste, and Format Painter controls. Third, you need a button or other control to perform an action. Buttons are the easiest controls to use, so that's what this chapter uses as a starting point. Figure 12-3 shows the entries you need in order to add one tab, one group, and one control to the Ribbon.

Figure 12-3:

The Custom UI Editor makes short work of Ribbon changes.

Figure 12-3:

The Custom UI Editor makes short work of Ribbon changes.

What's a callback?

You see the term callback used quite often when you work with the Ribbon. A callback is a special kind of an event. When the user clicks a button, the Ribbon receives the event. The event handler for the Ribbon then makes a call to any Sub you define for handling that event in VBA. A callback is more like a function call in VBA than it is an actual event handler. Callbacks can occur for a number of reasons, not just user actions. For example, you can receive a callback when the application loads.

Anyone who is familiar with older programming languages, such as C or C++, or who worked with the Windows Application Programming Interface (API), is already familiar with callbacks because these environments rely heavily on them. The Ribbon callback may sound like a new idea, but it has been around for quite some time.

This chapter gives you a good starting point for working with the Ribbon. You find, as the book progresses, other information about the Ribbon in specific applications. However, at some point, you need to know information about a Ribbon element that doesn't appear in this book. Microsoft provides detailed Ribbon information at http://msdn2.microsoft.com/en-us/ library/ms406047.aspx.

0 0

Post a comment