Results 1 to 6 of 6

Thread: Disable customized Menu Id

  1. #1
    Acolyte misi01's Avatar
    Join Date
    Jul 2011
    Location
    Stockholm,Sweden
    Posts
    31
    Articles
    0

    Disable customized Menu Id



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

    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
    Enable_disable_menu_button.xlsm

  2. #2
    Acolyte Andy Pope's Avatar
    Join Date
    Mar 2011
    Location
    London, England
    Posts
    27
    Articles
    0
    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
    Cheers
    Andy

    www.andypope.info

  3. #3
    Acolyte misi01's Avatar
    Join Date
    Jul 2011
    Location
    Stockholm,Sweden
    Posts
    31
    Articles
    0

    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
    PHP 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

  4. #4
    Acolyte Andy Pope's Avatar
    Join Date
    Mar 2011
    Location
    London, England
    Posts
    27
    Articles
    0
    Try the attached file.
    Attached Files Attached Files
    Cheers
    Andy

    www.andypope.info

  5. #5
    Acolyte misi01's Avatar
    Join Date
    Jul 2011
    Location
    Stockholm,Sweden
    Posts
    31
    Articles
    0

    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.

  6. #6
    Acolyte Andy Pope's Avatar
    Join Date
    Mar 2011
    Location
    London, England
    Posts
    27
    Articles
    0


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

    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.
    Cheers
    Andy

    www.andypope.info

Posting Permissions

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