View Full Version : Excel 2007 Ribbon
JKwan
10-20-2010, 05:17 PM
Just today, I started looking at 2007, it is quite a bit different than I used to. Especially, the ribbon! Does anyone have sample code to add an icon to the ribbon? Right now, none of my icons are there. Thanks.
Simon Lloyd
10-20-2010, 05:35 PM
What do you mean "add an icon"?
Simon Lloyd
10-20-2010, 05:47 PM
You can also take a look here which should help you with where everything has moved to http://www.thecodecage.com/forumz/general-news-updates/26031-microsoft-office-2003-2007-ribbon-locations.html
JKwan
10-20-2010, 05:58 PM
Thanks for the read, I will definitely take a look. As in add "icon", what I meant was adding a CommandBar, then a CommandButton.
Now, looking at my code, I do see my CommandButton under Custom Toolbar, so not a total lost. But I am not able to create a new "custom Toolbar" - just thru the excel interface. There is no "new toolbar", like Excel 2003. Seems that everything gets put into that Custom Toolbar, I would like to create my owe Toolbar and command buttons like with Excel 2003.
Simon Lloyd
10-20-2010, 06:11 PM
You will find them under the Add Ins tab, have you turned on the developers tab?
Simon Lloyd
10-20-2010, 06:14 PM
For another read and tutorial on how to customise the ribbon take a look at Ken Puls' excerpt from his new book http://www.excelguru.ca/node/93
Bob Phillips
10-21-2010, 12:08 AM
In 2007, if you want customise the ribbon, you need to define the changes in XML. For instance, this XML will add a group and a button to the Developer tab
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
<ribbon startFromScratch="false">
<tabs>
<tab idMso="TabDeveloper">
<group id="grpDevData" getLabel="getDevLabel">
<box id="boxDevDataImport" boxStyle="vertical">
<button id="btnDevTextToCols"
imageMso="FieldsMenu"
onAction="getDevAction"
getLabel="getDevLabel" />
</box>
</group>
</tab>
</tabs>
</ribbon>
</customUI>
You add the XML directly in the workbook via the CustomUI Editor http://openxmldeveloper.org/articles/customuieditor.aspx.
I use callbacks to set the labels, the getLabel, and so on in the XML, so you need code to do so, such as
Global Const ID_GROUP_DEV_DATA As String = "grpDevData"
Global Const ID_BUTTON_TEXT_TO_COLUMNS As String = "btnDevTextToCols"
Global Const LABEL_GROUP_DEV_DATA As String = "Data Functions"
Global Const LABEL_BUTTON_TEXT_TO_COLUMNS As String = "Text To Columns"
Sub getDevLabel(control As IRibbonControl, ByRef returnedVal)
Select Case control.ID
Case ID_GROUP_DEV_DATA: returnedVal = LABEL_GROUP_DEV_DATA
Case ID_BUTTON_TEXT_TO_COLUMNS: returnedVal = LABEL_BUTTON_TEXT_TO_COLUMNS
End Select.
End Sub
and so on. The icon is set via imageMso, which is getting a built-in image.
JKwan
10-21-2010, 06:04 AM
Thank you all for more info. I will take a look once I get home, since I don't have Office 2007 at the office.
JKwan
10-21-2010, 06:13 AM
xld:
Looking at your code and you said that it will add a group and button to the Developer tab, I was wondering (and I tried to do thru the Customization screen - without success) is to create a new tab, so I can stuff buttons into it. How do I do that with your code example? So, If I want a new tab call MyUtilities, then I would like a set of buttons in that tab. I refer to this method because that is what I do with Excel 2003.
Thanks again.
Bob Phillips
10-21-2010, 12:43 PM
You need to id the tab rather than use a built-in id
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
<ribbon startFromScratch="false">
<tabs>
<tab id="myUtilities" getLabel="rxdrwGetLabel" insertAfterMso="TabHome">
<group id="grpDevData" getLabel="getDevLabel">
<box id="boxDevDataImport" boxStyle="vertical">
<button id="btnDevTextToCols"
imageMso="FieldsMenu"
onAction="getDevAction"
getLabel="getDevLabel" />
</box>
</group>
</tab>
</tabs>
</ribbon>
</customUI>
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.