Developer: Overview of the new UI customization model (”RibbonX”)
Archival Notice: This post is no longer current and has been moved to the archive. Please read the new post replacing this one. Images and links in this post are not guaranteed to work.
After highlighting in a previous post the lack of user customization, it is time to look at customization from a developer’s point of view. If you are interested in background reading on the topic or want a look ahead, read the UI blog on developer topics.Office 2007’s Ribbon opens a new chapter for all Office and Windows developers. Except if you have done some Java UI development, you probably will have never encountered the UI programming methodology adopted by Office 2007. Most Office and Windows developers are used to programming the User Interface directly in their code: Whether it is Office, ATL, MFC or .NET’s Windows Forms, a developer always works with an object model that builds or modifies the user interface. For the Ribbon, there is no object model and the UI is not modified/specified with code.
The following SmartArt graphic outlines the process in which the Ribbon UI can be customized:

I admit the graphic looks rather simplistic, but I had trouble with creating a more complex one with graphics. Let me look at each of these steps in detail.

RibbonX code is XML code following an XML Schema provided by Microsoft. According to Wikipedia, “XML is a way of describing data and an XML file can contain the data too”. For the purposes of customizing the Office Ribbon UI, the XML code describes everything. All the information about size, location, visibility, label, ID, etc that developers are accustomed to specifying in code are specified in the RibbonX XML format. If you are totally unfamiliar with XML or its “relative” HTML, take a look at this XML Tutorial. I will showcase the particular syntax of RibbonX in subsequent posts and also show lots of examples.

The Ribbon Application of your choice (Access, Excel, Outlook, PowerPoint or Word) will read your RibbonX code and apply everything you specified in there to its own UI. A big catch with this is that you only get ONE chance to provide your RibbonX code. That means contrary to the usual Office and Windows UI development, the UI you can specify is rather static during the runtime of your add-in. This is a serious limitation compared to add-in development for previous Office versions. Some dynamic functionality is possible though and I will explore these in subsequent posts. When your add-in is unloaded, all the UI modifications you provided via RibbonX will be removed as well. In previous Office versions, a developer had to make sure to remove these things themselves, but Office 2007 takes care of that now.

The last piece in the new customization model is the actual add-in. In the RibbonX code, you specify “callbacks”. Callbacks are functions in your add-in code that Office calls under certain conditions. For example, you can specify a callback that is called by Office when it wants to know whether a particular control is visible or not. You could also specify a callback to have Office get the label for a control. Callbacks are the most important building block for dynamic behavior and adjustment to different localities.
My next posts will show you how to add a “Hello World” button to the first tab of a Ribbon application and show a message box with “Hello World” when you click on it. Each post will focus on different programming languages and situations from which you can do this.

June 1st, 2006 at 10:10
Patrick,
Glad to see that the train has left the station and you are getting on with posting these examples. I fumbled around some more last night trying to get the example procedure that Mr. White prepared in the article “Customizing the Office (2007) Ribbon UI for Developers Part 1 of 2 to work. Still no joy. I got a reply to a question posted in the Word private newsgroups that indicated Mr. White might have left out a step that modified the Content_Type file of the zip container. The poster wasn’t sure what the missing step was but since the error I am getting indicates the docm file contains unreadable content I am hopeful that the problem is simply a missing step and that you will have it cleared up when you get to your post on customizing with VBA.
Thanks for all your work here.
June 1st, 2006 at 10:18
Greg,
considering that I have a working example here it seems that it works.
Which private newsgroup are you referring to? The beta one? If yes, I don’t see your post there.
Patrick
June 1st, 2006 at 10:54
Patrick,
I posted the question in the Microsoft Private Word Newsgroup.
I don’t know anything about a private Beta group or how to access it.
I am not asking that you divert from your planned schedule to jump ahead, but I wanted to let you know what procedure I am trying and the outcome.
This is the procedure I followed but made changes accordingly (I think) for Word:
Adding Document-Based Add-ins to the Ribbon UI
The following steps describe the process to create a custom Ribbon UI in Excel 2007 that contains the components to call a custom macro:
Create a macro-enabled Excel workbook (I created a Word document) with one macro.
Create a file to customize the Ribbon UI by adding one tab, one group, and one button.
Specify a callback in the button to call the macro that you created in the document.
Modify the contents of the macro-enabled document container to point to the file that customizes the Ribbon UI.
Save the macro-enabled file, and then open it in Excel 2007 (I opened in Word).
To create an Open XML Formats file that is macro-enabled
Start Excel (Word).
In the Visual Basic Editor, double-click ThisWorkbook (ThisDocument) to open the code window.
Type the following VBA procedure, and then close the Visual Basic Editor.
Your macro should look similar to this:
Copy CodeSub MyMacro(ByVal control as IRibbonControl)
MsgBox(”Hello World”)
End Sub
Note The return value in VBA has to be a Variant data type.
Save the document as an Open XML Formats file that is macro-enabled and has the file name extension .xlsm (docm).
To create the XML file that contains the XML markup to modify the UI
Create a folder named customUI and add it to the desktop.
Open a new file in a text editor, and then save it as customUI.xml in the folder that you created.
Add the following code to the file:
Copy Code
(I used ThisDocument)
To modify files contained in the macro-enabled file container
Add a .zip extension to the file name of the macro-enabled file.
Double-click the file name to open it for viewing.
Add the customUI folder to the Zip container.
Extract the .rels file to the desktop. A folder named _rels containing the .rels file appears on the desktop.
Open the .rels file in the text editor.
Add the following line between the last element and the element, and then save and close the file:
Drag the _rels folder from the desktop to the Zip container file.
Remove the .zip extension from the container file.
Open the macro-enabled file in Excel 2007. The built-in Ribbon UI is replaced with the customized UI.
Click Large Button. The Hello World message is displayed.
If you do not see the message, make sure that macros are enabled in the workbook(document).
When I do this and try to open the document I get an error message that states the document contains content that cannot be opened and the details state the document is corrupt.
Thanks.
June 1st, 2006 at 17:24
Patrick,
The fellow posted back and said that in the Beta1 instructions there was a step to add the following line in the Content_Types file:
I tried that, but still no joy.
June 1st, 2006 at 17:49
I hear you. I’ll post the VBA example later tonight.
June 1st, 2006 at 19:58
It will be received like manna from heaven. Thank you ever so much.
November 5th, 2006 at 9:25
[…] The main purpose of my forums is to support the upcoming release of RibbonCustomizer. If you have a particular feature request, post it in the forums. […]