PDA

View Full Version : Ribbon preserve values on checkboxes



efernandes67
2017-04-13, 09:09 PM
Hi,

I am just starting in ribbon customization and I am having a little problem. In the ribbon I inserted two check boxes (see attached file) that are used to hide columns. This part is working well I suppose. My problem is that when I save the file and reopen it the check boxes do not preserve the values when the workbook was saved. I saw a post using custom properties, but I think its a little advanced since I just start with ribbon customization.

What do I need to do to make it work?

Regards,
Elio Fernandes

Ken Puls
2017-04-14, 05:16 AM
Your getPressed routine fires for each control indivdually, but you are checking both controls in each iteration. Since there is only one returnedVal that can be fed back, you're overriding it with the state of whatever the last control is in the list.

This version of the routine uses a Select case to check the control name and should react a bit better for you:


Public Sub rxClass_getPressed(control As IRibbonControl, ByRef returnedVal) Select Case control.ID
Case Is = "chkClass12"
With Worksheets("Sheet1").[oClass12]
If .Value = True Then
returnedVal = True
Else
returnedVal = False
End If
End With
Case Is = "chkClass34"
With Worksheets("Sheet1").[oClass34]
If .Value = True Then
returnedVal = True
Else
returnedVal = False
End If
End With
Case Else
MsgBox "I don't have a case for this control"
End Select


End Sub

efernandes67
2017-04-14, 01:39 PM
Thanks Ken, it works very well.