As part of my job, I debug and mitigate application compatibility issues with Windows Vista for customers who are migrating to the operating system. Along the way, I also get my fair share of Office 2007 questions (on which I am no expert) since these two products are, more often then not, being deployed together. (We call this DOVO - Desktop Optimization with Vista and Office. We like acronyms here at Microsoft.)

I came across an interesting issue today. My customer had an application which, for Office 2003, had created a new toolbar, and then used VBA to disable every other toolbar on the system (using the CommandBars object). They were calling out each CommandBar by name, so the process was inherently somewhat fragile. And, sure enough, on Office 2007, some things weren't disabled.

Now, there were a couple of different approaches we could take. One would be to just find out which CommandBar objects were left out, and snag them as well. The other is to just disable everything and only enable what you specifically want.

Then, on one of our internal discussion lists, somebody (who clearly knows Office better than I do) suggested just customizing the ribbon.

You know, because what is the value of having 9 tabs sitting up there when eight of them contain only controls that are grayed out? (And also because having everything crammed together on the Add-Ins tab with their tiny little icons looks like ... erm ... looks not so great.)

So, my next question was - how hard is that to set up?

And boy, I can't believe how easy it is.

First, I created a new docm document. I saved it to the desktop, and renamed it So, now I can open it like a Zip file.

I then created a new folder on  my desktop called customUI, and created an XML document inside of it called customUI.xml. I grabbed the schema for the customUI XML from here: I installed the xsd into the Visual Studio 2008 schema cache, and cooked up a quick and dirty XML file:

<customUI xmlns="" >
    <ribbon startFromScratch="true">
            <tab id="WorkInstruction" label="Work Instruction">
                <group id="SampleGroup1" label="Sample Group">
                    <button id="Button" imageMso="HappyFace" label="Insert Company Name" size="large" onAction="ThisDocument.InsertCompanyName" />

The startFromScratch attribute in the ribbon object is the key to clearing out everything that's there, so only the things you specifically add show up (which is a far better user experience than seeing all of the controls but having none of them work, in my opinion).

I then dragged that customUI folder into the zip file (really my docm file).

Then, I browsed to the rels folder, and edited the .rels xml file to add a relationship for the customUI so it became the following:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="">
    <Relationship Id="rId3" Type="" Target="docProps/core.xml"/>
    <Relationship Id="rId2" Type="" Target="docProps/thumbnail.wmf"/>
    <Relationship Id="rId1" Type="" Target="word/document.xml"/>
    <Relationship Id="rId4" Type="" Target="docProps/app.xml"/>
    <Relationship Id="someID" Type="" Target="customUI/customUI.xml" />

I then inserted this back into the zip file, and renamed it back to a docm file.

I had to add a bit of code to handle the button click, so I just took one of the samples and used its code:

Sub InsertCompanyName(ByVal control As IRibbonControl)
   Dim MyText As String
   Dim MyRange As Object
   Set MyRange = ActiveDocument.Range
   MyText = "Microsoft Corporation"
   MyRange.InsertBefore (MyText)
End Sub

And that was it. Less than half an hour, and I had a totally customized ribbon that used the more foolproof method of starting from scratch and then adding stuff than the method of starting with everything and disabling things by name until I had gotten rid of everything that I can think of.

Seriously, it was so cool to see this with such a minimal investment of time. Half an hour, tops. Makes me wonder why our own internal Office tools are still sitting in the add-ins tab...