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

Visto 1.785 veces
Saltar al primer mensaje no leído

KY

no leída,
7 jun 2010, 9:32:387/6/10
a 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

no leída,
13 jun 2010, 8:08:4713/6/10
a 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
Responder a todos
Responder al autor
Reenviar
0 mensajes nuevos