Custom Ribbon getPressed Issues

Josh 21 Reputation points
2022-04-22T16:59:34.553+00:00

I am trying to incorporate a "resume state" function in to an Excel Ribbon that has several toggle buttons. On close I save a list of Boolean variable to a spreadsheet and then on open it gathers them and applies them to the appropriate variables. That is working just fine. The problem lies when I try to send the Boolean through the getPressed callback function, the toggle buttons will press, run the onAction and then when the "getPressed" is called it reverts back to an unpressed state regardless of the Boolean value. If I remove the getPressed call from the XML everything works with exception to the ability to set the toggle button's state.

I am hoping someone can show me the error in my ways... thanks!

XML snippet:
<toggleButton
id="TB_Pause"
getLabel="GetLabel"
onAction="ButtonClicked"
getSize="GetSize"
image="Play_Pause"
getVisible="GetVisible"
getPressed="GetPressed"/>

VBA snippet:

Public Bool_Pause As Boolean

Dim myRibbon As IRibbonUI

Sub GetLabel(control As IRibbonControl, ByRef returnedVal)
    Select Case control.id
    Case "TB_Pause"
        Select Case Bool_Pause
            Case True: returnedVal = "Resume"
            Case False: returnedVal = "Pause"
        End Select
   End Select
End Sub

Sub ButtonClicked(control As IRibbonControl, Optional ByRef pressed As Boolean)
    Select Case control.id
        Case "TB_Pause"
            Bool_Pause = Not Bool_Pause
    End Select
    myRibbon.InvalidateControl (control.id)
End sub

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

Sub GetPressed(control As IRibbonControl, ByVal returnedVal)
    Select Case control.id
        Case "TB_Pause"
            returnedVal = Bool_Pause
    End Select
End Sub
Microsoft 365 and Office | Development | Other
Microsoft 365 and Office | Excel | For business | Windows
Developer technologies | Visual Basic for Applications
0 comments No comments
{count} votes

Accepted answer
  1. Tom van Stiphout 1,861 Reputation points MVP Volunteer Moderator
    2022-04-22T18:35:57.06+00:00

    Sub GetPressed(control As IRibbonControl, ByVal returnedVal)

    That should be ByRef, or the caller will never see the value.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.