Run Time Changes
In Visual Studio 2010 it is possible to show, hide and modify the Ribbon dynamically.
It is also possible to call the ribbon code from custom task panes and action panes.
This applies to both document level and application level.
Callbacks
A callback simply means that as part of the Ribbon definition you provide the name of a procedure to run when the control is clicked, changed, etc.
You can specify callbacks to update properties and perform actions from your UI at run-time
If multiple workbooks contain a procedure with the same callback name, there is no guarantee which one will be called.
Callbacks can also be used to change attribute values at run-time.
This can be done using a special interface IRibbonUI
Every control specified in the XML exposes its functionality by calls to callback procedures.
In most cases the callback procedure exposes an IRibbonControl interface that identifies the control.
The callback might pass other arguments as well that help to identify the state of the control.
<button id="Mybutton" onAction="MyButtonOnAction"/>
This must be declared public
Public Sub MyButtonOnAction(control As IRibbonControl)
If (control.Id = "MyButton") Then
End If
End Sub
control As IRibbonControl
The control parameter carries the unique id and tag properties of the control, which allows you to use the same callback procedure for multiple controls.
The IRibbonControl interface implements three read-only properties:
ID object - the control's id
Tag property - the control's tag attribute if defined in the XML
Context object - not use in Excel.
All attributes use camel-casing notation
Capitalise the first character of each word except the first !!
Most attributes for most controls can be set in this way
Using a Common Callback
The id property can be used to distinguish between controls if you have specified a common callback routine for several controls.
Is the Ribbon Visible
vis = CommandBars("Ribbon").Visible
Showing the Ribbon
Application.ExecuteExcel4Macro("SHOW.TOOLBAR("Ribbon","Visible")")
Globals Class
You can access the Ribbon from the Globals class.
Make sure that the tabs have unique IDs.
© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext