Determining Whether to Preselect a Checkbox

Let's say that you want to determine whether a checkbox is pressed when the Ribbon is loaded. To do this, you can handle the getPressed callback. The signature for that callback is the same as the onAction callback for a checkbox:

Sub OnGetPressed(ctl As IRibbonControl, ByRef pressed As Boolean)

ByRef is the default modifier for a parameter in Visual Basic and VBA, meaning that even if you don't specify ByRef, this modifier is implicitly defined. In effect these two signatures are identical. To set the pressed state of a checkbox, set the pressed argument before leaving the routine as shown in the following code:


OnGetPressed(ctl As IRibbonControl, If ctl.Id = "chkMyCheckBox" Then


pressed As


' Code to determine whether the


box should

be pressed

pressed = True

End If



Most of the get callbacks follow this pattern — they return a value using a ByRef parameter rather than using a function procedure.

0 0

Post a comment