OaklandJim
Well-known Member
- Joined
- Nov 29, 2018
- Messages
- 855
- Office Version
- 365
- Platform
- Windows
Ribboneers
I set up a generic onPress routine for the ribbon. It merely calls the element's onPress sub. See code below.
Works great with a toggle button. So I set it up to use with checkboxes too. I figger that there is an advantage to using that generic callback name in xml so it does not change even if the underling sub name does.
Anyway, that approach seems to not work with checkboxes. I have a checkbox-specific onPress callback sub. Works fine if I tell xml to use that sub for checkbox onPress callback. But, if I tell xml to use the generic callback (sub) the checkbox is not updated.
It seems that the ByRef "return value" param sent to my generic sub -- and passed along to the checkbox-specific sub -- does not get set by the checkbox-specific sub.
I must be missing something.
Shown below the code is immediate window output showing that the checkbox-specific sub fires when the generic one calls it but the return value param's value is not changed when accessed in the the generic sub.
>>> Debug.print output <<<
Sub GetPressed, control = T1G4Checkbox1,
call sub T1G4Checkbox1_getPressed
Sub T1G4Checkbox1_getPressed, pControl.id = T1G4Checkbox1
column is hidden, set control to true/checked. pvReturnedVal = True
Sub GetPressed after calling element-specific onPress sub, pvReturnedValue = False
I set up a generic onPress routine for the ribbon. It merely calls the element's onPress sub. See code below.
Works great with a toggle button. So I set it up to use with checkboxes too. I figger that there is an advantage to using that generic callback name in xml so it does not change even if the underling sub name does.
Anyway, that approach seems to not work with checkboxes. I have a checkbox-specific onPress callback sub. Works fine if I tell xml to use that sub for checkbox onPress callback. But, if I tell xml to use the generic callback (sub) the checkbox is not updated.
It seems that the ByRef "return value" param sent to my generic sub -- and passed along to the checkbox-specific sub -- does not get set by the checkbox-specific sub.
I must be missing something.
Shown below the code is immediate window output showing that the checkbox-specific sub fires when the generic one calls it but the return value param's value is not changed when accessed in the the generic sub.
VBA Code:
' Generic GetPressed Sub
'In all cases, call the element-specific getPressed
'sub passing along the two ByRef params so the
'pvReturnedValue param can be set by the sub that is called.
'By convention, that sub will be named with the id followed
'by "_getPressed"
Sub GetPressed( _
ByRef pControl As IRibbonControl, _
ByRef pvReturnedValue As Variant)
Debug.Print Chr(10) & "Sub GetPressed, control = " & pControl.id & ", "
Debug.Print "call sub " & pControl.id & "_getPressed"
Application.Run pControl.id & "_getPressed", pControl, pvReturnedValue
Debug.Print Chr(10) & "Sub GetPressed after calling element-specific onPress sub, pvReturnedValue = " & pvReturnedValue
End Sub
Sub T1G4Checkbox1_getPressed(pControl As IRibbonControl, ByRef pvReturnedVal As Variant)
Debug.Print Chr(10) & "Sub T1G4Checkbox1_getPressed, pControl.id = " & pControl.id
' Set checked/unchecked (pressed) based on hidden status of a column
If ThisWorkbook.Worksheets("Sheet1").Range("Header_ColTest").EntireColumn.Hidden _
Then
pvReturnedVal = True
Debug.Print "column is hidden, set control to true/checked. pvReturnedVal = " & pvReturnedVal
Else
pvReturnedVal = False
Debug.Print "column is NOT hidden, set control to false/unchecked. pvReturnedVal = " & pvReturnedVal
End If
End Sub
>>> Debug.print output <<<
Sub GetPressed, control = T1G4Checkbox1,
call sub T1G4Checkbox1_getPressed
Sub T1G4Checkbox1_getPressed, pControl.id = T1G4Checkbox1
column is hidden, set control to true/checked. pvReturnedVal = True
Sub GetPressed after calling element-specific onPress sub, pvReturnedValue = False