How to Build a Ribbon for Microsoft Office 2007 and 2010
The new Microsoft Office 2010 uses the same ribbon interface already familiar from Office 2007. There's hardly any major differences between the two. However, in some cases you may discover your Office 2007 ribbon doesn't show in Office 2010. By using a few tips you can make your UI compatible with both.
Tools You Need
- Microsoft Visual Studio 2008 or 2010
- Custom UI Editor for Microsoft Office (Download)
Creating a New Tab in Microsoft Office Word 2007 and 2010
In this example we are going to create a new tab in Word. To do that we will create a new Word file, add some ribbon XML to it by using Custom UI Editor, then view the tab in both versions of Word. This will also work with other Microsoft Office applications (Excel, PowerPoint or Outlook).
To create a new ribbon tab in Word 2007 and 2010:
- Launch Microsoft Office Word 2007 and create a new file "Progress Report.docm." When creating the file make sure you have selected the "Macro Enabled" option.
- Open "Progress Report.docm" file in Custom UI Editor by using the File > Open command.
- Add Custom UI Parts for Office 2007 and 2010 by using commands from the Insert menu. The final solution will appear like this:
- The file "CustomUI14.xml" is used by the Office 2010 application. Paste this code in "CustomUI14.xml":
Conversely, "CustomUI.xml" is used by the Office 2007 application. Paste this code in "CustomUI.xml":
- Use the Validate command from the Custom UI Editor toolbar to verify your .xml is free from errors.
- Go to File > Save and exit Custom UI Editor.
- Launch Word 2007 or 2010 and open "Progress Report.docm." The "Demo" tab we created should now be displayed in both applications.
As you can see, it's very easy to build a ribbon for any of the Microsoft Office applications. I've built complex dynamic ribbons that work great in both versions of Office, and by using this procedure you won't need to change any code whatsoever.
Summary
The ribbon XML code for both version of add-ins is identical. The only difference is in these two lines of code:
- For Office 2010:
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
- For Office 2007:
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
Troubleshooting
Some typical errors you may encounter are:
- File contains corrupted data
This can occur if you are using File > Open command in Custom UI Editor. You must not open an .xml file, instead (if you are following the example above) you need to open "Progress Report.docm" in Custom UI Editor. After you open the Word file in Custom UI Editor you can then just paste the contents of your .xml file in Custom UI Editor. - Failed to find Office control by ID
This happens when you use an invalid Office ID. Please ensure that the idMso entry that is causing an error exists for the application you're developing for, and that it is spelled correctly. Sometimes an Office ID for Word may not work in an Excel or PowerPoint add-in so please make sure you're using a correct ID for a correct application. To check the correctness of a control ID you may download the list of control identifiers here and check. This link is for Office 2010 control identifiers. - Element <group> is not expected in <menu>, or Element <x> is not expected in <y>
Try moving the element <x> from the <y> container and place it in another container at a higher level. Some items are not allowed to be sub-items in all types of containers, so play with moving the element that's causing the error higher up in the hierarchy chain.
Online Resources
- Check my bookmarks on this topic at Delicious:
http://www.delicious.com/mrspreadsheet/ribbon
- Download a list of Microsoft Office User Interface Control Identifiers from Microsoft Downloads:
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=3f2fe784-610e-4bf1-8143-41e481993ac6