Results 1 to 2 of 2

Thread: Enable all checkboxes in ribbon

  1. #1

    Enable all checkboxes in ribbon



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

    Hello everyone I have three checkboxes in ribbon( I created with Custom UI editor with Microsoft Office) with that code :
    Code:
     <checkBox id ="F20"label="F20"tag="F20"onAction="Show_Column" />
    <checkBox id ="F21"label="F20 F21 LCI"tag="F-21 LCI"onAction="Show_Column" />
    <checkBox id ="F22"label="F22"tag="F22"onAction="Show_Column" />
    
    and it runs Show_Column macro and it is fine.
    What I need to do is to make it all enabled(checked) when I run this macro

    Code:
    Sub Button29_Click(control As IRibbonControl)
      Sheets("Main Sheet").Columns("B:ZZ").Hidden = True
    End Sub
    Can you help me about that?

  2. #2
    Conjurer WizzardOfOz's Avatar
    Join Date
    Sep 2013
    Location
    Australia
    Posts
    184
    Articles
    0
    Minor change you need to tell the ribbon to redraw itself

    XML code
    <customUI
    xmlns="http://schemas.microsoft.com/office/2006/01/customui"
    onLoad="R_onLoad">
    <ribbon >
    <tabs >
    <tab id="Tab1" label="MyTab">
    <group id="Group1" label="ChBox">
    <checkBox id="F20" label="F20" tag="F20" getPressed="Chkbox_getPressed" onAction="Chkbox_onAction"/>
    <checkBox id="F21" label="F21" tag="F21" getPressed="Chkbox_getPressed" onAction="Chkbox_onAction"/>
    <checkBox id="F22" label="F22" tag="F22" getPressed="Chkbox_getPressed" onAction="Chkbox_onAction"/>
    </group >
    </tab >
    </tabs >
    </ribbon >
    </customUI >

    VBA code
    Option Explicit


    Public gobjRibbon As IRibbonUI
    Public bChk(20 To 22) As Boolean 'save the button status here


    Function GetChkBox(ByVal sString) As String 'convert ID to 20 to 22
    GetChkBox = Right(sString, 2)
    End Function


    'Callback for customUI.onLoad
    Sub R_onLoad(ribbon As IRibbonUI)
    Set gobjRibbon = ribbon 'save it so that iut can redraw itself, see Invalidate later
    bChk(20) = True 'are yours starting as true/false
    bChk(21) = True
    bChk(22) = True
    End Sub


    'Callback for F20 getPressed
    Sub Chkbox_getPressed(control As IRibbonControl, ByRef Button)
    Debug.Print "Chkbox_getPressed", control.ID 'debug print so you can follow the order, remove once done
    Button = bChk(GetChkBox(control.ID)) 'is it on or off and reset it to what it should be based on the array
    End Sub


    'Callback for F20 onAction
    Sub Chkbox_onAction(control As IRibbonControl, pressed As Boolean)


    bChk(GetChkBox(control.ID)) = bChk(GetChkBox(control.ID)) Xor True 'update it
    Debug.Print "Chkbox_OnAction Start", control.ID
    gobjRibbon.InvalidateControl (control.ID) 'tell it that it needs to redraw itself
    Debug.Print "Chkbox_OnAction End", control.ID
    End Sub

Posting Permissions

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