Consulting

Results 1 to 10 of 10

Thread: Excel 2007 Ribbon

  1. #1
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location

    Excel 2007 Ribbon

    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.

  2. #2
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    What do you mean "add an icon"?
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  3. #3
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    You can also take a look here which should help you with where everything has moved to http://www.thecodecage.com/forumz/ge...locations.html
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  4. #4
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location
    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.

  5. #5
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    You will find them under the Add Ins tab, have you turned on the developers tab?
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  6. #6
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    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
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    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...muieditor.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

    [vba]


    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
    [/vba]

    and so on. The icon is set via imageMso, which is getting a built-in image.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  8. #8
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location
    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.

  9. #9
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location
    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.

  10. #10
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    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>
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •