Welcome To The Ribbon
With the introduction of Office 2007 came the Ribbon. A whole new way of navigating the User Interface. This was a great enhancement to prior versions. It is also one of the new elements developers of office automation had to get used to. For years we have been programming our own menu and toolbars. How do you create a ribbon with those nice tabs? Soon there was the wish for a tool to develop your own ribbon and do your own customizations. During the beta of 2007 it didn’t take long before the first tools arrived. Passionate developers have been developing customization tools since then. When you do a search on the internet you will find a couple of tools available for you. Most of them very good. There is one simple one that also made its appearance and that is the one I have been using. It is called the [CustomUI Editor] and the good news is you can get this one for free! You will find the download here (Read the note at the end of the post – for Win XP users!)
Before diving into creating your own ribbon you should know the following distinction. In Office 2010 it is possible to create your own tabs in the ribbon by using the [Customize Ribbon] under the file options in the specified application. For Excel, PowerPoint and Word you can create file based ribbons with the customUI editor. This is not possible for Microsoft Access. For Access there are other options which we will describe later.
So the first thing you have to know is do I want to customize my ribbon used by the application or do you want to create a ribbon which is attached to the file (project) you are working on. Let us take a look at the first option.
- Creating a Ribbon (Tab) attached to the application
In this scenario you are creating a new Tab in your exsisting application ribbon. This tab will show up every time you start your application like for instance Excel. You can simply create your own tabs by using the [customize ribbon] under the File – Options. In the picture you will see that I created a new tab called “Maurice” with one button on it the “Name Manager” in Excel.
I took the following steps to create this:
– Open Excel
– Customize Ribbon
– Click button [New Tab] on the right side of the screen (also choose rename to set your own name)
– Click button [New Group] on the right side of the screen (also choos rename to set your own name)
Now for the last part that got me confused. I would have expected a button with [New Button] but there is not. You can now go to the left part of the screen and just ‘drag’ the options you like to your own tab and group. The nice thing is I dragged the ‘name manager’ option and this button actually works without me doing any programming at all!
- Removal of your own tab
To remove the various options in your tab or remove the tab as a whole one might expect a [Delete Button]. You will not find it. Rightclick on your tab (or group or buttons) and choose remove. This will make your tab disappear forever.
- Creating a file based ribbon using the CustomUI editor
If you want to add your own ribbon to a specific file you can not use the [customize ribbon] option in the application. At that point you need to write either your own .xml or use a tool for this. That is where the CustomUI Editor comes in.
So let us take a look on how to create your own Tab attached to your project. In the following example I used a blank Excel file and added the custom .xml to that file. As you can see in the picture above the tab [Custom Tab] is actually the tab I created using the CustomUI Editor. When I close the file but leave Excel open that tab will disappear but the tab [Maurice] will stay visible. Ok now how did I go about creating that custom tab:
– Download and install the CustomUI Editor
– Open Excel and create a blank excelfile and save it to the directory of your choice
– Open the UI editor and click on the Open Folder icon in the menubar
– Browse to the directory where you have saved your excel file and click open
– You now have a blank file in the UI Editor
– First you have to make a decision whether you want to make a tab for Office 2007 or Office 2010. You do so by clicking on the Insert option in the menubar. For the example I chose the Office 2010 option. You still have a blank window but an indicator on the left has shown up indicating that this is 2010 xml markup. In the picture I posted here you will see that the actual xml is created in an earlier version of Office namely 2007. This code will work in 2010 as well the only downside is that you can not make any customizations the the Backstage View of you Ribbon. To do so you need to set a reference to the 2010 schema which is: [http://schemas.microsoft.com/office/2009/07/customui] without the brackets! But as I stated the xml in the picture does work with Office 2010 as well because we are just adding a Ribbon with one tabe to the file.
- Examine the XML in the example
In the picture you will see the XML markup which will make up the tab in the example file. Let me explain a little more about that.
The first lines you see are mandatory. They describe the schema used by xml. Furthermore every line starts with <> and should be closed with its counterpart which is </> which closes the set of references. So if you look closely you will see that the first reference is <ribbon> which should have a counterpart </ribbon> which closes the reference. It might be an option to create a template with the first three lines because you will use those for every xml part. Write them down and paste them into a notepad text file for later use.
The following references explain themselfs. You need to create a tab in the Tabs object so you should start the following sequence:
It is vital that every reference you make gets a unique identifier. So if you create a new group the groupID should be unique and cannot be the same as the one used in a earlier reference. Now lets take a look at the button reference:
<button id=”cmdCustomerData” label=”Check Customer Data…” imageMso=”ExportExcel” size=”large” onAction=”showImportform”/>
- button id : is the identifier which makes the button unique on the tab. You can name this anything you like
- label : this can be anything you like and will appear under the icon
- imageMSO: a default reference to an existing icon used by the Office 2010 engine
- size : the size of the icon which will appear on the button. In contrast to what you might think small icons are referred to as “normal”
- onAction : if you have created your own macro which you want to call you use the option with referral to your macroname
The last option is optional and can be left out.
When you are done click the save button in the UI Editor. Your xml is now attached to your file. Changes can be made by opening the UI Editor again en opening the specified file.
So go ahead and let’s see what you can do. Download the UI Editor and start creating your own tabs! use the first few lines from the sample above and you are good to go.
Important for Win XP users : Before you install the Custom UI Editor do this:
Run Windows Update, and in Optional Updates pick .NET framework 2 or 3.
After you installed it, run Windows Update again to see if there are patches for it.
This version of the Custum UI Editor gives you an option to insert a customUI.xml file for Excel 2007-2010
and/or a customUI14.xml file only for Excel 2010 into your 2007-2010 workbook.
When you do not want to work with new stuff from Excel 2010 (like Backstage View for example), then you can
use the Office 2007 Custom UI Part option to add your RibbonX to workbooks that you use in Excel 2007
and Excel 2010. If there is no customUI14.xml file when you open the workbook in Excel 2010, it will load
the customUI.xml file.
But if you want to insert (for example) a button in the Office Button menu when you open your file in Excel 2007 and a button in Backstage View when you open the workbook in Excel 2010, then you must insert the RibbonX in both the xml files with the Custum UI Editor.