I'm very pleased that Wiley Publishing has encouraged me to post an excerpt from our new book RibbonX - Customizing the Office 2007 Ribbon, which can now be found at Amazon.com and other online retailers.
Chapter 2 of the book focuses on how to access the XML layer of the new Office 2007 file formats. We cover the hard way (renaming the file to a zip format), using the free CustomUI Editor tool, and also discuss XML Notepad. The excerpt that I have picked to share, from pages 41-43 of Chapter 2, actually contains two parts.
- The first part discusses how to create an XML template in the CustomUI Editor, which can then be applied to other files later.
- The second part provides some notes about using the CustomUI Editor, specifically exposing the "Gotchas" that are evident in this tool.
I chose this section because it was referred to throughout the book, rather than reproduce the framing XML code. I also chose this section because Wiley has generously allowed me to post the entire Chapter 7, focusing on the comboBox and dropDown elements, on my site. By reproducing this section of Chapter 2 here it means that you'll be able to follow the entire Chapter 7, which will be up in a day or two.
The Chapter Excerpt
Storing Customization Templates in the CustomUI Editor
You may encounter scenarios in which you want to refer to a custom UI that you previously developed. Again, you can use the CustomUI Editor to store and access custom templates, as shown in Figure 2-14.
Figure 2-14: CustomUI code templatesTo demonstrate the ease and benefits of setting up your own templates, use Notepad to create a new text file on your computer and enter the following code into it:
[xml]
[/xml]
Save the file in the folder Program Files\CustomUI Editor\Samples with the filename RibbonBase.xml.
The Program Files\CustomUI Editor\Samples path assumes that you used the default installation path for the Microsoft Office 2007 Custom UI Editor. If you installed the program to a different path, you will need to modify the preceding instruction accordingly.
If you cannot access this file in Windows Vista, it is due to the User Access Control feature restricting your permissions. You will need administrative rights in order to store these templates in the specified folder.
Finally, open the CustomUI Editor and select the Samples menu. If your new file is in the right place, you should now see the RibbonBase entry on the list. Click it and voilà ! There is your XML template, which you can use to start all future Ribbon customizations!
Now that you have this on your menu, how do you use it? It’s quite simple, actually. Just create your new file, open it in the CustomUI Editor, and select your RibbonBase from the menu. It copies all of the code into your file for you, and you’re good to go! What a great way to get a head start.
If you open a file that has customizations in place already and select your template, all of your current customizations will be overwritten with the template’s code. You can, of course, close the file without saving and not lose your current work.
Some Notes About Using the CustomUI Editor
The CustomUI Editor is a fantastic utility that makes editing XML code much easier. As with all programs, however, it is not perfect. You should be aware of some CustomUI Editor “gotchas†before you dive right in:
- The CustomUI Editor does check the form of your XML tags, as well as make sure that you only use attributes that are defined in the XML schema. What it does not do, however, is check that you have provided valid attributes within the quotes. (You’ll learn about attributes later, but be aware that you can still receive errors even if your XML is well formed.)
- While writing and debugging your RibbonX code, it is very tempting to open your file in both the application and the CustomUI Editor at the same time. Trying to save the file in the CustomUI Editor while the file is open in the Office application will result in an error. In addition, even if you close the document that you are editing in the Office application and then save it in the CustomUI Editor, the editor will overwrite any changes that you made while editing your document in the application! It is much safer to close the file in each application before making changes in the other.
If you forget and make changes in the application, you can preserve those changes by saving the file to a new filename. At least then it can be a reference if you want to incorporate the changes into the original document.)
- The CustomUI Editor does not have a Find/Replace utility, so if you’re planning to do large-scale editing on your XML, you may want to copy your information to another program, edit it, and then copy it back.
- When working on files that have more lines of XML than will fit on the screen, the CustomUI Editor has an annoying habit of refreshing the screen so that your cursor is always on the last line of the screen. If you are trying to make an edit and want to read the information three lines below, this can become a major irritation. Here, again, you may want to copy your XML data into another editor to work on it and then paste the updated copy back into the CustomUI Editor.
7 thoughts on “An Excerpt from RibbonX – Customizing the Office 2007 Ribbon”
Tks for your sharing.
LVD
You're welcome. 🙂
Also, Chapter 7 is now posted on my main site.
Ken - Just ordered your book! Looking forward to reading it.
I managed to modify the ribbon by creating the XML file, and it looks great. Now, I need to make changes to the custom menu I defined. Tried a simple change - just changed the label for a button.
- Pasted the updated XML in the Office 2007 Custom UI Editor
- Validated the XML
- Opened the xlsm file which had the custom menu
- Saved the file - hoping to update it.
Nothing changed. So, how does one update the already defined custom ribbon?
Also, is there a documentation on the Office 2006 Custom UI Editor. I just downloaded from the web - and it said it was a pre-release version.
Any pointers would help!
Hi Kavindra,
It's difficult to answer your question without seeing your code, to be honest.
With regards to the CustomUI Editor, there isn't any documentation that I'm aware of, no.
kavindra -- Use the Custom UI Editor to open the XLSM. The XLM and any custom icons can be edited using the editor, the XLM validated, callbacks generated to be pasted into the module, and then the XLSM saved. Do have to be sure that the XLSM is not open in Excel, since "last in, wins"
Paul -
You mean "XML" for eXtensible Markup Language, which is the brand new whiz bang stuff, as opposed to "XLM" for Excel 4 Macro Language, which is the very old whiz-bang, which they'd deprecate if it weren't still so useful.
Hi Ken,
Great book as far as I've gotten. Have both CustumUI editor and XML notepad operational in Vista and created RibbonBase.xml. I put RibbonBase.xml in the installation Samples folder and it shows as a slectable option. However, no matter which Sample option I choose, Vista throws an exception refusing to load my Samples selection. I suppose it is a UAC issue, but I can't fix it. Any suggestion appreciated.
Frank