Ribbon control.Label and control.Image of button in ExcelDNA 0.26

1,782 views
Skip to first unread message

KY

unread,
Jun 7, 2010, 9:32:38 AM6/7/10
to Excel-Dna
Intellisense tells me there are 3 readonly properties on an
IRibbonControl; Context, Id and Tag. I want to change the image and
label when a user clicks a ribbon button, something like:

Public Sub OnButtonPressed(control as IRibbonControl)
If control.Id = "Button2" And control.Image = "Off" Then
Call ServerStartRTDServer()
control.Image = "On"
control.Label = "Real Time On"
Else
Call ServerTerminateRTDServer()
control.Image = "Off"
control.Label = "Real Time Off"
End If
End Sub

How do I get access to the ribbon images and labels outside of setting
them in customui.xml?

Govert van Drimmelen

unread,
Jun 13, 2010, 8:08:47 AM6/13/10
to Excel-Dna
Hi,

The Ribbon extensibility model is a bit unusual.

There is no opportunity to set the 'label' or 'image' property of the
button after it is created, but there are 'getLabel' and 'getImage'
callbacks that you can set up.
To get Excel to refresh your control (or the whole Ribbon extension)
you need to set an onLoad callback (on the customUI element) which
receives an IRibbonUI interface for you to keep. This interface has
two methods - Invalidate and InvalidateControl - which you call when a
control should be refreshed.

ExcelDna can helps with the implementation of the getImage callback -
call the ExcelRibbon.LoadImage method (probably as
base.LoadImage(imageId) in your code) with the imageId of the picture
you want to show - this way you can load the images you specify in
the .dna file.

All of this can be elegantly wrapped in some classes without too much
trouble.

I suggest the following references:
Articles on MSDN:
Customizing the 2007 Office Fluent Ribbon for Developers (3 parts)
http://msdn.microsoft.com/en-us/library/aa338202(office.12).aspx
Making object wrappers to ease the scenario you have:
Custom Task Panes, the Office Fluent Ribbon, and Reusing VBA Code in
the 2007 Office System http://msdn.microsoft.com/en-us/library/bb194905(v=office.12).aspx
Some Excel 2010 info:
Customizing the backstage view in Excel 2010:
http://msdn.microsoft.com/en-us/library/ee815851(v=office.14).aspx
Customizing context menus in Excel 2010:
http://msdn.microsoft.com/en-us/library/ee691832(v=office.14).aspx
Tab activation and scaling in Excel 2010:
http://msdn.microsoft.com/en-us/library/ee691834(v=office.14).aspx

Other links:
Andy Pope's Ribbon Editor http://www.andypope.info/vba/ribboneditor.htm
Ron de Bruin's site http://www.rondebruin.nl/ribbon.htm
Free chapter 'Excel 2007 VBA Programmer's Reference'
http://www.oaltd.co.uk/Excel2007ProgRef/Default.htm
(The section on 'Updating Controls at Run Time' is what you're asking
about.)

Hope this gets you started.
I'm sure any examples you can post here will be greatly appreciated.

Regards,
Govert
Reply all
Reply to author
Forward
0 new messages