Setting Ribbon Properties

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.

References

I suggest the following references:

Articles on MSDN:

Some Excel 2010 info:

Other links:


Also note that a ribbon designed in VSTO can be exported to xml, which gives a <customUI ...> tag that can be used directly in Excel-DNA, though the ribbon handlers have to be re-implemented.

Last edited Jun 3, 2014 at 11:14 AM by govert, version 5

Comments

zzstuzor May 4, 2015 at 8:05 PM 
Hey Govert,
Does this mean I can't dynamically set the .Visible or .Enabled property? I have a Login and Logout button, and I either need to rename the button label from "Log in" to "Log out", or to be able to have both buttons and just hide one or the other accordingly. I'm converting from a VSTO ribbon where it was possible and this is the last thing I need to finish the conversion.
Cheers
Stu