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.

Load the ribbon customisation at run-time from VBA
Access 2007 - Application.LoadCustomUI (sribbon)
Project 2010 - ActiveProject.SetCustomUI (sribbon)

Is the Ribbon Visible
vis = CommandBars("Ribbon").Visible
Showing the Ribbon


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 camal-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.

Globals Class

You can access the Ribbon from the Globals class.
Make sure that the tabs have unique IDs.

Office 2010

Dim objRibbonTab As Microsoft.Office.Tools.Ribbon.RibbonTab 

There are ActivateTab and ActivateTabMso methods

ribbon.ActivateTab "TabAddIns"; 

ribbon.ActivateTabQ - this is used for tabs shared between multiple add-ins 

This also requires an additional string parameter that specifies the namespace of the add-in

Office 2007

Using SendKeys

Using Microsoft Active Accessibility API
This is a COM based technology which provides the IAccessible interface
MSAA is a legacy API that was introduced in Windows 95
Microsoft UI Automation is the new accessibility model for Windows
link -

link - 

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext