Laurent Sarlette
Laurent Sarlette

Reputation: 1

Simulate a click on a toggleButton in a custom-made Ribbon

I created a custom Ribbon in Excel with multiple ToggleButtons using Office RibbonX Editor. When I click them 1 by 1 everything works (display a certain meeting type on a calendar Yes or No).

I want to add two buttons to "select all" and "unselect all" ToggleButtons. All the meeting types are displayed or removed from my calendar but the status of the ToggleButtons doesn't change accordingly.

The following code forces a status when my Ribbon is changed. Each of the ToggleButtons calls this macro by using the "getpressed" syntax in XML:

XML:

<toggleButton id="TB1" onAction="OnTB1Click" getPressed="Option_Enabled"/>

VBA:

Sub Option_Enabled(control As IRibbonControl, ByRef returnedVal)
    returnedVal = True
End Sub

I want to force a status of one specific toggleButton for which I have defined a keytip (TBa):

XML:

<toggleButton id="TB1" keytip="TBa" onAction="OnTB1Click" getPressed="Option_Enabled"/>

How can I call this toggleButton to force it's status?

I believe it must be close to my previous Option_Enabled macro but putting the right name to define the right IRibbonControl object. Do I have to use the id, the keytip?

Upvotes: 0

Views: 55

Answers (1)

jkpieterse
jkpieterse

Reputation: 3006

You'll have to add the getPressed callback to the togglebuttons. E.g:

<toggleButton id="foobar" getPressed="foobar_getPressed"/>

and here is the associated VBA code:

Sub foobar_getPressed(control As IRibbonControl, ByRef returnedVal)
    returnedVal = SomeFunctionReturningTrueOrFalse()
End Sub

Then when the ribbon is refreshed, it will automatically call this callback to retrieve the correct toggleButton state.

Upvotes: 0

Related Questions