0

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?

1
  • The way your Ribbon XML-code is set up, OnTB1Click will run when you click the TB1 toggle button and Option_Enabled will run when Excel draws your ribbon. Since Option_Enabled always returns True - your button will always appear pressed. You need OnTB1Click to set some value that will be checked when Option_Enabled is run to decide if the button should appear pressed or not. Then your "select all"/"unselect all"-buttons can set all those values to False and then invalidate the whole ribbon or the individual controls so they will be redrawn and Option_Enabled will be run again. Commented Feb 19 at 13:13

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi - thank you but this is what I already did. My point is that it works when the ribbon is refreshed but I want to force a status change without refreshing the ribbon. In other words, when I click on a button named "select all", I want to change the status of all my ToggleButtons in the ribbon to TRUE.
You then simply invalidate the ribbon, it takes care of all callbacks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.