Disable checkbox on Custom ribbon on worksheet active or inactive

krishnaoptif

Board Regular
Joined
Sep 17, 2010
Messages
140
Hi guys
i want to enable checkboxes from the custom ribbon only for two sheets and for rest of sheet it should be disabled.

Please check below code which i have written.

<group id="Group2" label="SELECT OTHER VIEW OTPIONS"><checkbox id="Showfew" label="Show Few" getpressed="ShowCodes_getPressed" onaction="ShowCodes_onAction" getenabled="GetEnabled"><checkbox id="ShowOther" label="Show Other" getpressed="ShowAbbreviations_getPressed" onaction="ShowAbbreviations_onAction" getenabled="GetEnabled">This is my VBA Code to disable during workbook opening time. i have also written..


Code:
        Public Sub GetEnabled(control As IRibbonControl, ByRef returnedVal)
                If ActiveSheet.Name = "ItemCreator" Or ActiveSheet.Name = "ItemUpdator" Then
                    returnedVal = True
                Else
                    returnedVal = False
                End If
        End Sub


how can i run this GetEnabled public sub procedure on Worksheet_Activate() and Worksheet_Deactivate() events</checkbox></checkbox></group>
 
Last edited:

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Hi Experts, It is so surprising that i did not receive any response yet on this..

This is really very urgent for me to finish asap..

Regards,
Krishna
 
Upvote 0
Whenever a sheet is activated, you'll need to invalidate the checkbox control, which will cause the GetEnabled procedure to be called. Assuming that your code assigned the Ribbon object to a variable, let's say MyRibbon, first place the following code into the code module for ThisWorkbook...

Code:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
    Call UpdateCheckBox
End Sub

Then include the following code with your other VBA callbacks (change the name of the checkbox accordingly)...

Code:
Sub UpdateCheckBox()
    'Executed when a sheet is activated
    MyRibbon.InvalidateControl ("Checkbox1")
End Sub

Hope this helps!
 
Upvote 0
Hello Mr Domenic,
Thanks for the great help in changing the checkbox values basis on sheet change by using this code. but i want to know one more thing, if i will choose any other sheet apart from "ItemCreator" and "ItemUpdator" then my checkbox should be disabled...
Can you please provide code for else condition in below code ?

Code:
            Public Sub Checkbox1_getPressed(control As IRibbonControl, ByRef returnedVal)
                If ActiveSheet.Name = "ItemCreator" Then
                    returnedVal = TRUE
                ElseIf ActiveSheet.Name = "ItemUpdator" Then
                    returnedVal = FALSE
                Else
                   'here you need to provide the code to disable the checkbox.. or is there any other method to disable this ?


              
                End If
                
            End Sub
 
Last edited:
Upvote 0
In addition to getPressed, which changes the value for your checkbox, you can use the getEnabled VBA callback procedure to enable/disable the checkbox. First, add the following RibbonX code to your checkbox control...

HTML:
getEnabled="Checkbox1_getEnabled"

Then you can use the following VBA callback procedure...

Code:
Public Sub Checkbox1_getEnabled(control As IRibbonControl, ByRef returnedVal)
    If ActiveSheet.Name = "ItemCreator" Then
        returnedVal = True
    ElseIf ActiveSheet.Name = "ItemUpdator" Then
        returnedVal = False
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,400
Messages
6,119,292
Members
448,885
Latest member
LokiSonic

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top