Enable all checkboxes in ribbon

cagataybaser

New member
Joined
Aug 14, 2014
Messages
13
Reaction score
0
Points
0
Hello everyone I have three checkboxes in ribbon( I created with Custom UI editor with Microsoft Office) with that code :
Code:
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff] <[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#800000][SIZE=2][COLOR=#800000]checkBox [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#ff0000][SIZE=2][COLOR=#ff0000]id[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff] =[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#000000]"[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]F20[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#000000]"[/COLOR][/SIZE][SIZE=2][COLOR=#ff0000][SIZE=2][COLOR=#ff0000]label[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]=[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#000000]"[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]F20[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#000000]"[/COLOR][/SIZE][SIZE=2][COLOR=#ff0000][SIZE=2][COLOR=#ff0000]tag[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]=[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#000000]"[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]F20[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#000000]"[/COLOR][/SIZE][SIZE=2][COLOR=#ff0000][SIZE=2][COLOR=#ff0000]onAction[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]=[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#000000]"Show_Column[/COLOR][/SIZE][SIZE=2][COLOR=#000000]"[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff] />
<[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#800000][SIZE=2][COLOR=#800000]checkBox [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#ff0000][SIZE=2][COLOR=#ff0000]id[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff] =[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#000000]"[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]F21[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#000000]"[/COLOR][/SIZE][SIZE=2][COLOR=#ff0000][SIZE=2][COLOR=#ff0000]label[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]=[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#000000]"[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]F20 F21 LCI[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#000000]"[/COLOR][/SIZE][SIZE=2][COLOR=#ff0000][SIZE=2][COLOR=#ff0000]tag[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]=[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#000000]"[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]F-21 LCI[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#000000]"[/COLOR][/SIZE][SIZE=2][COLOR=#ff0000][SIZE=2][COLOR=#ff0000]onAction[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]=[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#000000]"[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][COLOR=#000000]Show_Column[/COLOR][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#000000]"[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff] />
<[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#800000][SIZE=2][COLOR=#800000]checkBox [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#ff0000][SIZE=2][COLOR=#ff0000]id[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff] =[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#000000]"[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]F22[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#000000]"[/COLOR][/SIZE][SIZE=2][COLOR=#ff0000][SIZE=2][COLOR=#ff0000]label[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]=[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#000000]"[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]F22[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#000000]"[/COLOR][/SIZE][SIZE=2][COLOR=#ff0000][SIZE=2][COLOR=#ff0000]tag[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]=[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#000000]"[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]F22[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#000000]"[/COLOR][/SIZE][SIZE=2][COLOR=#ff0000][SIZE=2][COLOR=#ff0000]onAction[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]=[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#000000]"[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff][COLOR=#000000]Show_Column[/COLOR][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#000000]"[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff] />
[/COLOR][/SIZE][/COLOR][/SIZE]
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:
[SIZE=2][COLOR=#0000ff]Sub Button29_Click(control As IRibbonControl)
  Sheets("Main Sheet").Columns("B:ZZ").Hidden = True
End Sub[/COLOR][/SIZE]

Can you help me about that?
 
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
 
Back
Top