layout | title |
---|---|
page |
Ribbon Customization |
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.
Excel-DNA can help 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.
To create dynamically set up ribbons, you need to build the xml also in a callback method (GetCustomUI). The RibbonVB Example in the Samples repository shows a project that handles dynamic ribbon elements (also handling menu visibility, dynamic screentip and image display, dropdowns and recursive menus) as well as context menus (cell, row, column etc.), utilization of an inbuilt commandbar and handling of VBE.Interop Command buttons.
Another VB Example is in the tutorials: RibbonBasics, a Csharp Example can be found in Ribbon.
If you look for the imageMso identifiers for the built-in ribbon controls, these can easily be looked up when customizing the ribbon (context menu "customize menu" in the ribbon) and hovering over the control of interest (the imageMso is shown in brackets after the control name).
To create dynamically set up ribbons, you need to build the xml also in a callback method (GetCustomUI). The below example shows a class that handles dynamic ribbon elements (also handling menu visibility, dynamic screentip and image display, dropdowns and recursive menus) as well as context menus (cell, row, column etc.), utilization of an inbuilt commandbar. To create dynamically set up ribbons, you need to build the xml also in a callback method (GetCustomUI). The RibbonVB Example in the Samples repository shows a project that handles dynamic ribbon elements (also handling menu visibility, dynamic screentip and image display, dropdowns and recursive menus) as well as context menus (cell, row, column etc.), utilization of an inbuilt commandbar and handling of VBE.Interop Command buttons.
Another VB Example is in the tutorials: RibbonBasics, a Csharp Example can be found in Ribbon.
If you look for the imageMso identifiers for the built-in ribbon controls, these can easily be looked up when customizing the ribbon (context menu "customize menu" in the ribbon) and hovering over the control of interest (the imageMso is shown in brackets after the control name).
-
Customizing the 2007 Office Fluent Ribbon for Developers (3 parts)
-
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
- Customizing the backstage view in Excel 2010
- Customizing context menus in Excel 2010
- Tab activation and scaling in Excel 2010
- Andy Pope's Ribbon Editor (new, additional support for office 2010)
- Ron de Bruin's site with details of the Excel 2013 Backstage changes.
- Discussion about Excel-DNA ribbons and the QAT.
- Shareware tool ribboncreator
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.