Disable customized Menu Id

misi01

New member
Joined
Jul 13, 2011
Messages
31
Reaction score
0
Points
0
Location
Stockholm,Sweden
I have a customized ribbon that includes the following code:-
Code:
        <group id="customGroup1">
          <splitButton id="mySplitButton" size="large">
            <button id="SHB_button" getEnabled="get_enabled_SHB_button" image="SHB_small" label="Option"/>
            <menu id="SHB_Menu" getEnabled="get_enabled_SHB_menu" itemSize="normal">
              <!-- use itemSize = large or use normal -->
              <button id="Button_1" getEnabled="get_enabled_button1" imageMso="TableInsert" label="Button 1" onAction="Run_button1"/>
              <button id="Button_2" getEnabled="get_enabled_button2" imageMso="TableInsert" label="Button 2" onAction="Run_button2"/>
            </menu>
          </splitButton>
        </group>

I have also created a diddy workbook with 2 sheets called Enable and Disable (which I've attached). Needless to say, if I select the Disable sheet, I want the button (SHB_Button) to be disabled as well as the SHB_Menu option.

What I'm seeing is that it seems as if you have to disable both Button_1 and Button_2 for me not to be able to select the Option button_id. If either is enabled, then I can still open the Option button.

Am I missing something ? I assumed that if I disabled SHB_button and/or SHB_Menu then buttons 1 & 2 would never be shown by clicking on the Option "option". I'll include my "disabling" code as well
Code:
Private Sub Worksheet_Activate()
Dim answer As String

Application.EnableEvents = True         ' Just in case ....
' Ensure the callback is performed that will change the buttons to disabled
'
g_SHB_button_Enabled = False
g_rbxIRibbonUI.InvalidateControl gRBX_SHB_BUTTON

' I've also included the following code to no avail
g_SHB_Menu_Enabled = False
g_rbxIRibbonUI.InvalidateControl gRBX_SHB_MENU
   
End Sub
View attachment Enable_disable_menu_button.xlsm
 

Andy Pope

New member
Joined
Mar 22, 2011
Messages
43
Reaction score
0
Points
0
Location
London, England
Website
www.andypope.info
Excel Version(s)
2016
You need to disable the actual split button.
So define a const for the splitbutton and invalidate that as well.

Code:
Public Const gRBX_SHB_SPLITBUTTON = "mySplitButton"

Code:
g_SHB_button_Enabled = False
g_rbxIRibbonUI.InvalidateControl gRBX_SHB_SPLITBUTTON
g_rbxIRibbonUI.InvalidateControl gRBX_SHB_BUTTON
 

misi01

New member
Joined
Jul 13, 2011
Messages
31
Reaction score
0
Points
0
Location
Stockholm,Sweden
Thanks for the reply Andy but that didn't seem to work

(I'm aware of the fact that the slightest error in one's ribbon code results in nothing happening rather than an error). I changed the UI code to be
Code:
<splitButton id="mySplitButton" getEnabled="get_enabled_mySplitButton" size="large">
(not sure whether the getenabled was necessary). Then I changed the code to
Code:
Public Const gRBX_SHB_SPLITBUTTON = "mySplitButton"
Public g_SHB_SPLITBUTTON_Enabled As Boolean
and on the activate of the sheet
Code:
 g_SHB_SPLITBUTTON_Enabled = False
  g_rbxIRibbonUI.InvalidateControl gRBX_SHB_SPLITBUTTON
  g_SHB_button_Enabled = False
  g_rbxIRibbonUI.InvalidateControl gRBX_SHB_BUTTON
as well as
Code:
'Callback for mySplitButton getEnabled
Sub get_enabled_mySplitButton(control As IRibbonControl, ByRef returnedVal)
MsgBox "In enabled_mySplitButton"
returnedVal = g_SHB_SPLITBUTTON_Enabled
End Sub

but I was still able to open the ID SHB_Menu (the button itself was disabled) and see/run the macros Run_button_1/2. Nor did I ever hit the MSGBOX in get_enabled_mySplitButton
 

misi01

New member
Joined
Jul 13, 2011
Messages
31
Reaction score
0
Points
0
Location
Stockholm,Sweden
Thanks Andy

My mistake was to think I could delete the lines
Code:
g_SHB_Menu_Enabled = False
g_rbxIRibbonUI.InvalidateControl gRBX_SHB_MENU

Many thanks again (I have to wonder though, how the hell did you figure out that the splitbutton needed to be disabled as well ???)

I'll assume from now on, that if you want to disable something in a customized ribbon, then all items "above" it need to be disabled for it to work.
 

Andy Pope

New member
Joined
Mar 22, 2011
Messages
43
Reaction score
0
Points
0
Location
London, England
Website
www.andypope.info
Excel Version(s)
2016
Well the split button is a compound control.

-SplitButton
--Button
--Menu
----Menu Items

You can enable parts of the control, as you were doing, or you can simply effect the SplitButton part to alter the whole control.
 
Top