question

Josh-0223 avatar image
0 Votes"
Josh-0223 asked Josh-0223 commented

Custom Ribbon getPressed Issues

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


office-vba-devoffice-excel-itprooffice-addins-dev
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

TvanStiphout avatar image
1 Vote"
TvanStiphout answered Josh-0223 commented

Sub GetPressed(control As IRibbonControl, ByVal returnedVal)

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

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@TvanStiphout Thank you, thank you, thank you! I knew I was overlooking something simple.

0 Votes 0 ·