Results 1 to 3 of 3

Thread: Ribbon preserve values on checkboxes

  1. #1

    Ribbon preserve values on checkboxes



    Register for a FREE account, and/
    or Log in to avoid these ads!

    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
    Attached Files Attached Files

  2. #2
    Administrator Ken Puls's Avatar
    Join Date
    Mar 2011
    Location
    Nanaimo, BC, Canada
    Posts
    2,317
    Articles
    57
    Blog Entries
    14
    Excel Version
    Excel Office 365 Insider
    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:

    Code:
    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
    Ken Puls, FCPA, FCMA, MS MVP

    Learn to Master Your Data at the Power Query Academy (the world's most comprehensive online Power Query training), with my book M is for Data Monkey, or our new Power Query Recipe cards!

    Main Site: http://www.excelguru.ca -||- Blog: http://www.excelguru.ca/blog -||- Forums: http://www.excelguru.ca/forums
    Check out the Excelguru Facebook Fan Page -||- Follow Me on Twitter

    If you've been given VBA code (a macro) for your solution, but don't know where to put it, CLICK HERE.

  3. #3
    Thanks Ken, it works very well.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •