Vous êtes sur la page 1sur 11

Change the Ribbon in Excel 2007 or Excel 2010 Ron de Bruin (last updated 5-June-2011) Go back to the Excel

tips page Contents Things we must do and understand before we start First example More RibbonX Examples (sample workbooks) Find the Control, Group and Tab names Find the names of the button images RibbonX Tips RibbonX templates for the Sample XML menu in the UI Editor More Information

Things we must do and understand before we start If you want to change the Ribbon in Excel 2007 or Excel 2010 you must add RibbonX(xml) to a file named customUI.xml and/or customUI14.xml that is inside your Excel file. What, files that are inside a Excel file ?. Excel 2007-2010 files are really zip files so if you change the extension to zip and open the file in your zip program you see that there are a few folders and a file inside the zip. If you want a easy way to insert RibbonX into a Excel 2007-2010 workbook, then I suggest you download and install the new version of the Custom UI Editor here : http://openxmldeveloper.org/archive/2006/05/26/CustomUIeditor.aspx 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. See this page for a example : http://www.rondebruin.nl/ribbonx20072010.htm Open the Custom UI Editor.

You see that there are 5 menu buttons on the toolbar menu in the UI editor. Open : Open the Excel file that you want to edit (change the Ribbon for this file) Save : Save the RibbonX in the file that you have open in the UI editor (not possible to save when the file is open in Excel) Insert Icons : Insert your own icons in the file (icons will be saved in the file) Validate : Validate your RibbonX so you are sure that there are no typos Generate Callbacks : This will create macros(callbacks) for each onAction you have in the RibbonX. Select all callbacks and copy them in a normal module in your workbook. When you open a Excel file in the Custom UI Editor you can right click on the file name and choose : Office 2007 Custom UI Part Or use Office 2010 Custom UI Part Or you can use the Insert menu to choose one of the two options.

It creates the customUI14.xml file if you choose Office 2010 Custom UI Part and the customUI.xml file if you choose Office 2007 Custom UI Part. After you choose one option or both, you can enter or paste your RibbonX in the right window.

First example This example add RibbonX that create a button on the Home tab when you open your file in Excel 2007 or in Excel 2010. Because we not use something new for 2010 we can add the RibbonX only to the customUI.xml file ("Office 2007 Custom UI Part") . 1: Open a new workbook and save it as Book1.xlsm (Excel Macro-Enabled workbook)

2: Close the workbook 3: Open Book1.xlsm in the Custom UI Editor 4: Right click on the File name in the Custom UI Editor or use the Insert menu 5: Choose "Office 2007 Custom UI Part" to create the customUI.xml file 6: Paste the RibbonX below in the right window Note: If there is no customUI14.xml file it will load the customUI.xml also in Excel 2010.
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"> <ribbon> <tabs> <tab idMso="TabHome" > <group id="customGroup1" label="My Group" insertAfterMso="GroupEditingExcel"> <button id="customButton1" label="Click Me" size="large" onAction="Macro1" imageMso="HappyFace" /> </group> </tab> </tabs> </ribbon> </customUI>

7: Save your changes in the Custom UI Editor (click on the Save button) 8: Close the Editor 9: Open the File in Excel 10: Alt F11 11: Insert Module 12: Copy the macro below in the Module
Sub Macro1(control As IRibbonControl) MsgBox "Hi There" End Sub

13: Click on the Save button in the VBA editor 14: use Alt q to close the VBA editor 15: Test the workbook in 2007 and/or in 2010

For a example to load different RibbonX in 2007 and 2010 visit this page http://www.rondebruin.nl/ribbonx20072010.htm

More RibbonX examples You can download 8 Excel files here with basic RibbonX examples for Excel 2007 and Excel 2010. Download Example Excel files Last Updated : 27-June-2010

Add custom group in built-in tab.xlsm Add menu and buttons to Backstage or Office Button.xlsm Custom tab for Favorite Groups and buttons.xlsm Custom tab for your favorite macros part 1.xlsm Custom tab for your favorite macros part 2.xlsm Dictator(1).xlsm Dictator(2) With_Custom_Tab.xlsm Disable-Visible-Repurposing.xlsm Note 1: when you create your menus with Application.CommandBars in Excel 97-2003 you have code to create the menu and delete the menu. In Excel 2007-2010 when you use RibbonX to customize the ribbon this is different, when you close or deactivate the workbook it will automatic remove your customizations. Note 2: The files are working OK in Excel 2007 and 2010. If you want to load different RibbonX for Excel 2007 and Excel 2010 see : Load different RibbonX when opening file in Excel 2007 or 2010 http://www.rondebruin.nl/ribbonx20072010.htm

Find the Control, Group and Tab names You see that I use idMso="VisualBasic" to point to a built-in control. But how do you find the names of the controls ? Microsoft files for Excel 2007 and Excel 2010 Download this file from the Microsoft site: Office 2007: Lists of Control IDs Download this file from the Microsoft site: Office 2010: Office Fluent User Interface Control Identifiers I create my own versions of the files for Excel above to make it easier. Note: If you disable macros you can't use the files. Download the Excel 2007 version Download the Excel 2010 version If you are only looking for the names of the controls in the built-in groups on the Ribbon see : http://www.rondebruin.nl/xmlribbongroups.htm Download the Word and PowerPoint version for Excel 2007 : Download the Word version Download the PowerPoint version

Tip: ContextMenu Add-in for Office 2010 This add-in from Microsoft add the name of the ContextMenu in every Context menu(Right click menu's). This is a very easy way for developers to find the idMso of the menu so they can use it in the RibbonX. Note: Only In 2010 you can change the ContextMenu's with RibbonX. http://code.msdn.microsoft.com/contextmenusaddin See also: How do I Change a ContextMenu in Excel http://www.rondebruin.nl/contextmenu.htm

Find the names of the button images You can see that I use imageMso="HappyFace" to use the built-in image I want. But how do you find the names of all the images? Microsoft files for Excel 2007 and Excel 2010 Download this file from the Microsoft site Office 2007 : Icons Gallery Download this file from the Microsoft site Office 2010 : Icons Gallery Control Image Add-in for Excel 2007 and Excel 2010 (made by Jim Rech) Tip Jim's add-in displays the images on buttons in the Ribbon (by adding a new tab), he has tried to remove most or all duplicate images and, in the case of Excel 2007, added a few images not in the MS list. Download it from my site File date (16-Nov-2010), also working in the 64 bit version of Excel 2010. Note 1: There is one small problem on this moment when you have this add-in loaded in Excel 2007: If you select All Commands In the Choose commands from dropdown in the QAT customize dialog with this add-in loaded you will get a error 400 a lot of times (you can hold the Enter key, faster than clicking OK). Microsoft fixed this bug in Excel 2010. Note 2: Jim describes on the add-in's worksheet how he got the image names that he uses. If you are curious change the IsAddin property of the add-in to False to see the worksheet.

For Excel 2007: You can use John Walkenbach's mso image browser for Excel 2007 workbook. Download it from my site

RibbonX Tips 1: How do I use my own icons in the Ribbon

<--- ron.png 1) Download my picture ron.png on your desktop (right click on the picture and use Save Picture As) 2) Open the file "Book1.xlsm" from the first example in the Custom UI Editor. 3) Click on the Insert Icons button or use the Insert menu to insert the file ron.png. You see it now below the custumUI file in the Custom UI Editor, maybe you must click on the + before customUI.xml if you not see it. Then change this imageMso="HappyFace" to image="ron" Click on the Save button in the Custom UI Editor and open the file "Book1.xlsm" in Excel and you see my nice face on the ribbon. imageMso = Built-in icon image = Your own icon

For more information see this page : Images on custom Ribbon controls http://www.rondebruin.nl/getimage.htm

2: Display and Hide Tabs, Groups, and Controls on the Microsoft Office Ribbon In one of the 8 Excel files above you can find RibbonX examples to Hide Disable or Display Enable Ribbon controls/groups/Tabs. But how can you Hide or make a Tab, Group or Control visible with VBA code ? My MSDN Articles : Display and Hide Tabs, Groups, and Controls on the Microsoft Office Ribbon (Part 1 of 2) http://msdn.microsoft.com/en-us/library/ee390805(office.11).aspx

Display and Hide Tabs, Groups, and Controls on the Microsoft Office Ribbon (Part 2 of 2) http://msdn.microsoft.com/en-us/library/ee633442(office.11).aspx Or on my own site : Hide or Display Custom Ribbon Tab/Group/Control with getVisible http://www.rondebruin.nl/hidevisible.htm

3: Enable or Disable custom Ribbon buttons in Excel 2007-2010 Enable or Disable custom Ribbon buttons in Excel 2007-2010 http://www.rondebruin.nl/enable.htm

4: loss of state of the global IRibbonUI Ribbon object There is a common problem when you are working with the Ribbon with RibbonX and VBA. The ribbon object (which is initialized when Excel loads your file) can loose its reference to the ribbon, which means your code can no longer tell Excel to update your ribbon customizations. There is simply no easy built-in way to recover the handle to the Ribbon when there are problems in or with your code. The only way to fix it is to close reopen your workbook, not a very user friendly way. Visit this page for a solution for this nasty problem http://www.rondebruin.nl/ribbonstate.htm

5: How do I Change a ContextMenu in Excel with VBA and RibbonX (Excel 2010) Visit the page below for examples and example workbooks How do I Change a ContextMenu in Excel http://www.rondebruin.nl/contextmenu.htm

6: Examples to change Backstage View in Excel 2010 There is one example in the download above but on the page below there are more examples.

How do I change Backstage(File) in Excel 2010 http://www.rondebruin.nl/backstage.htm

7: How do I create Galleries in the Ribbon There are many controls that you can add to the Ribbon and one of them is a Gallery. On this page you can download a few example workbooks that are maybe useful if you want to create your own Gallery on the Ribbon. Galleries in the Ribbon http://www.rondebruin.nl/galleries.htm

8: How do I fill a dropdown on the Ribbon with values from a range In the download you find one file from Jim Rech and one from me based on Jim's example. I my example you can see how you can use the dropdown value in another macro. Download DropDown.zip

9: Dictator examples and Hide the MRU("Most Recently Used") file list There are two dictator examples in example files but you see that the MRU list is still there. Note: in Excel 2010 this is no problem anymore, see this page for a example http://www.rondebruin.nl/backstage.htm There is no built-in option to disable the MRU("Most Recently Used") file list in the Office button menu. Try this example file that create a new tab on the Ribbon and hide/disable a few controls with RibbonX and with VBA code from Jim Rech disable the MRU list. Part from the comments in the code from Jim: Because there is apparently no way to disable the MRU list on the Office Menu directly we clear it by setting Application.RecentFiles.Maximum to 0. Since this action clears the MRU list in the registry we first backup its contents to the registry as well as number of files the user is showing in it. We use the registry in case VB variables are cleared. Download the example file Please give feedback if you have problems or suggestions with the code.

If you test the Dictator examples you also notice that it will not disable/hide everything. With VBA code you must also hide the formula bar, status bar and right click menus.

10: Hide/Show the whole Ribbon with VBA You can use this VBA example posted by Jim Rech to Hide/Show the whole Ribbon and QAT.
Sub HideRibbon() Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",False)" End Sub Sub ShowRibbon() Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",True)" End Sub

Only in Excel 2010 you can use this to toggle the view of only the Ribbon CommandBars.ExecuteMso "MinimizeRibbon" See this site for a function to check the state of the Ribbon http://www.accessribbon.de/en/index.php?FAQ:19

11: Edit the Ribbon with a Add-in Try this Add-in : RibbonX Visual Designer Add-in (made by Andy Pope) http://www.andypope.info/vba/ribboneditor.htm Now that you know how you can use the Custom UI Editor to save the RibbonX in a workbook maybe you want to try this old workbook to create the RibbonX for a custom tab on the Ribbon. XMLCreator-1.5 File date: 5 March 2007

12: How do I change the QAT (Quick Access Toolbar) Menu for favorite macros in Excel 2007-2010 (for all workbooks) Menu for favorite macros in Excel 2007-2010 (for one workbook) Add missing built-in commands to the QAT or Ribbon Add buttons to the QAT and customize the images of the buttons

13: Customize Contextual tabs in Excel 2007 and Excel 2010

Learn how to customize Contextual tabs in Excel 2007 and Excel 2010 http://www.rondebruin.nl/contextualtabs.htm

RibbonX templates for the XML menu in the UI editor On the Insert menu in the Custom UI Editor you see that there is a menu called "Sample XML" It is easy to have your own menu templates there so you can insert it quick in any workbook you want. You only have to make a few changes after you insert it from the Sample menu and you are ready. But In the UI editor you cannot save the RibbonX directly to an xml file and use that in the Insert>Sample XML menu. It is only possible to save the RibbonX directly in a Excel file. But you can do this: Make your template menu in the UI editor and validate and test the RibbonX in a test workbook. Then copy the RibbonX in a Notepad file and save it with the name you want. Then change the extension from txt to xml If you not see the extensions of your files do this: 1: Open Windows Explorer 2: Win XP : Click on Tools>Folder Options 3: Vista or Windows 7 : Click on Organize>Folder and Search Options 4: On the View tab uncheck Hide extensions for known file types" Then copy the template xml file in the samples folder. C:\Program Files\CustomUIEditor\Samples Or if you have a 64 bit machine C:\Program Files (x86)\CustomUIEditor\Samples After you open the UI editor you will see your template file in the Sample menu of the UI editor and you can insert it in any workbook you want. You can download a zip file here with 11 XML files with RibbonX from the example workbooks that you can download in the "More RibbonX examples" section so you can paste them in the

"Samples" folder to test it. XMLSamples.zip File date: 27-June-2010 (8 for the "Office 2007 Custom UI Part" and 3 for the "Office 2010 Custom UI Part")

More information See the links in this part "Excel 2007-2010 Ribbon and QAT pages" of my Tips page http://www.rondebruin.nl/tips.htm Customizing the 2007 Office Fluent Ribbon for Developers (MSDN) http://msdn2.microsoft.com/en-us/library/aa338202.aspx Read Chapter 14 (RibbonX) of this great book: Excel 2007 VBA Programmer's Reference http://www.oaltd.co.uk/Excel2007ProgRef/Default.htm Book: RibbonX: Customizing the Office 2007 Ribbon http://www.amazon.com/RibbonX-Customizing-Office-2007-Ribbon/dp/0470191112 RibbonX Visual Designer Add-in (made by Andy Pope) http://www.andypope.info/vba/ribboneditor.htm