Excel Custom Ribbon toggle button dependency









up vote
0
down vote

favorite












I'm trying to put together a custom menu, and I want 2 of the toggleButtons:"chkToggle1" and "chkToggle2" to exclude each other, meaning that when 1 is checked the other is not and vice versa.



 <checkBox id="chkToggle1" getLabel="onGetLabel" getScreentip="onGetScreentip" getSupertip="onGetSupertip" getPressed="GetPressed" onAction="tgl_ClickAddin" />
<checkBox id="chkToggle2" getLabel="onGetLabel" getScreentip="onGetScreentip" getSupertip="onGetSupertip" getPressed="GetPressed" onAction="tgl_ClickAddin" />


Can you guys give any ideas on how I can do that? Ideally there should be a way to get the pressed value from another control by control.id without using global variables, but Google is not helping me, maybe you can.










share|improve this question























  • Not gonna answer since I don't have much time atm, but you might want to check out if OptionButton does the trick for you.
    – M.Douda
    Nov 9 at 8:46










  • Option buttons would work great, but i don't see them under Ribbon controls, am I missing something?
    – Dumitru Daniel
    Nov 9 at 9:00










  • It can be done, but your question is rather "broad" - you don't provide any starting point with code you've tried. Since you use the get attributes you're familiar with the three-part series of articles about customizing the Ribbon: docs.microsoft.com/en-us/previous-versions/office/developer/…? Could you use the edit link below the question to include the onAction code you have for that including the declarations for the RibbonUI, etc.
    – Cindy Meister
    Nov 9 at 11:06














up vote
0
down vote

favorite












I'm trying to put together a custom menu, and I want 2 of the toggleButtons:"chkToggle1" and "chkToggle2" to exclude each other, meaning that when 1 is checked the other is not and vice versa.



 <checkBox id="chkToggle1" getLabel="onGetLabel" getScreentip="onGetScreentip" getSupertip="onGetSupertip" getPressed="GetPressed" onAction="tgl_ClickAddin" />
<checkBox id="chkToggle2" getLabel="onGetLabel" getScreentip="onGetScreentip" getSupertip="onGetSupertip" getPressed="GetPressed" onAction="tgl_ClickAddin" />


Can you guys give any ideas on how I can do that? Ideally there should be a way to get the pressed value from another control by control.id without using global variables, but Google is not helping me, maybe you can.










share|improve this question























  • Not gonna answer since I don't have much time atm, but you might want to check out if OptionButton does the trick for you.
    – M.Douda
    Nov 9 at 8:46










  • Option buttons would work great, but i don't see them under Ribbon controls, am I missing something?
    – Dumitru Daniel
    Nov 9 at 9:00










  • It can be done, but your question is rather "broad" - you don't provide any starting point with code you've tried. Since you use the get attributes you're familiar with the three-part series of articles about customizing the Ribbon: docs.microsoft.com/en-us/previous-versions/office/developer/…? Could you use the edit link below the question to include the onAction code you have for that including the declarations for the RibbonUI, etc.
    – Cindy Meister
    Nov 9 at 11:06












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'm trying to put together a custom menu, and I want 2 of the toggleButtons:"chkToggle1" and "chkToggle2" to exclude each other, meaning that when 1 is checked the other is not and vice versa.



 <checkBox id="chkToggle1" getLabel="onGetLabel" getScreentip="onGetScreentip" getSupertip="onGetSupertip" getPressed="GetPressed" onAction="tgl_ClickAddin" />
<checkBox id="chkToggle2" getLabel="onGetLabel" getScreentip="onGetScreentip" getSupertip="onGetSupertip" getPressed="GetPressed" onAction="tgl_ClickAddin" />


Can you guys give any ideas on how I can do that? Ideally there should be a way to get the pressed value from another control by control.id without using global variables, but Google is not helping me, maybe you can.










share|improve this question















I'm trying to put together a custom menu, and I want 2 of the toggleButtons:"chkToggle1" and "chkToggle2" to exclude each other, meaning that when 1 is checked the other is not and vice versa.



 <checkBox id="chkToggle1" getLabel="onGetLabel" getScreentip="onGetScreentip" getSupertip="onGetSupertip" getPressed="GetPressed" onAction="tgl_ClickAddin" />
<checkBox id="chkToggle2" getLabel="onGetLabel" getScreentip="onGetScreentip" getSupertip="onGetSupertip" getPressed="GetPressed" onAction="tgl_ClickAddin" />


Can you guys give any ideas on how I can do that? Ideally there should be a way to get the pressed value from another control by control.id without using global variables, but Google is not helping me, maybe you can.







excel vba checkbox ribbon-control ribbonx






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 9 at 11:02









Cindy Meister

13.6k102034




13.6k102034










asked Nov 9 at 8:30









Dumitru Daniel

7810




7810











  • Not gonna answer since I don't have much time atm, but you might want to check out if OptionButton does the trick for you.
    – M.Douda
    Nov 9 at 8:46










  • Option buttons would work great, but i don't see them under Ribbon controls, am I missing something?
    – Dumitru Daniel
    Nov 9 at 9:00










  • It can be done, but your question is rather "broad" - you don't provide any starting point with code you've tried. Since you use the get attributes you're familiar with the three-part series of articles about customizing the Ribbon: docs.microsoft.com/en-us/previous-versions/office/developer/…? Could you use the edit link below the question to include the onAction code you have for that including the declarations for the RibbonUI, etc.
    – Cindy Meister
    Nov 9 at 11:06
















  • Not gonna answer since I don't have much time atm, but you might want to check out if OptionButton does the trick for you.
    – M.Douda
    Nov 9 at 8:46










  • Option buttons would work great, but i don't see them under Ribbon controls, am I missing something?
    – Dumitru Daniel
    Nov 9 at 9:00










  • It can be done, but your question is rather "broad" - you don't provide any starting point with code you've tried. Since you use the get attributes you're familiar with the three-part series of articles about customizing the Ribbon: docs.microsoft.com/en-us/previous-versions/office/developer/…? Could you use the edit link below the question to include the onAction code you have for that including the declarations for the RibbonUI, etc.
    – Cindy Meister
    Nov 9 at 11:06















Not gonna answer since I don't have much time atm, but you might want to check out if OptionButton does the trick for you.
– M.Douda
Nov 9 at 8:46




Not gonna answer since I don't have much time atm, but you might want to check out if OptionButton does the trick for you.
– M.Douda
Nov 9 at 8:46












Option buttons would work great, but i don't see them under Ribbon controls, am I missing something?
– Dumitru Daniel
Nov 9 at 9:00




Option buttons would work great, but i don't see them under Ribbon controls, am I missing something?
– Dumitru Daniel
Nov 9 at 9:00












It can be done, but your question is rather "broad" - you don't provide any starting point with code you've tried. Since you use the get attributes you're familiar with the three-part series of articles about customizing the Ribbon: docs.microsoft.com/en-us/previous-versions/office/developer/…? Could you use the edit link below the question to include the onAction code you have for that including the declarations for the RibbonUI, etc.
– Cindy Meister
Nov 9 at 11:06




It can be done, but your question is rather "broad" - you don't provide any starting point with code you've tried. Since you use the get attributes you're familiar with the three-part series of articles about customizing the Ribbon: docs.microsoft.com/en-us/previous-versions/office/developer/…? Could you use the edit link below the question to include the onAction code you have for that including the declarations for the RibbonUI, etc.
– Cindy Meister
Nov 9 at 11:06












1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










In my XML for the workbook I've got:



<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad = "RibbonOnLoad">
<ribbon>
<tabs>
<tab id="customTab" label="Contoso" insertAfterMso="TabHome">
<group id="customGroup" label="Contoso Tools">
<checkBox id="chkToggle1" tag="chkToggle1" getLabel="onGetLabel" getScreentip="onGetScreentip" getSupertip="onGetSupertip" getPressed="GetPressed" onAction="tgl_ClickAddin" getEnabled="GetEnabled" />
<checkBox id="chkToggle2" tag="chkToggle2" getLabel="onGetLabel" getScreentip="onGetScreentip" getSupertip="onGetSupertip" getPressed="GetPressed" onAction="tgl_ClickAddin" getEnabled="GetEnabled" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>


I've Added a Sheet to my workbook called RibbonReference (Which I'd recommend setting .Visible = xlSheetVeryHidden) and then added the following to a Module:



Option Explicit
Dim rib As IRibbonUI
Public ControlTag As String

Private Declare Function ShellExecute _
Lib "shell32.dll" Alias "ShellExecuteA" ( _
ByVal hWnd As Long, _
ByVal Operation As String, _
ByVal Filename As String, _
Optional ByVal Parameters As String, _
Optional ByVal Directory As String, _
Optional ByVal WindowStyle As Long = vbMinimizedFocus _
) As Long

#If VBA7 Then
Public Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)
#Else
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)
#End If
#If VBA7 Then
Function GetRibbon(ByVal lRibbonPointer As LongPtr) As Object
#Else
Function GetRibbon(ByVal lRibbonPointer As Long) As Object
#End If
Dim objRibbon As Object
CopyMemory objRibbon, lRibbonPointer, LenB(lRibbonPointer)
Set GetRibbon = objRibbon
Set objRibbon = Nothing
End Function
Public Sub RefreshRibbon()
If rib Is Nothing Then
Set rib = GetRibbon(ThisWorkbook.Sheets("RibbonReference").Cells(2, 1).Value)
Else
rib.Invalidate
End If
End Sub
Sub RibbonOnLoad(ribbon As IRibbonUI)
Set rib = ribbon
Debug.Print "ribbon:-", ObjPtr(ribbon)
ThisWorkbook.Sheets("RibbonReference").Cells(2, 1).Value = ObjPtr(ribbon)
End Sub
Sub GetEnabled(control As IRibbonControl, ByRef enabled)
If control.Tag = ControlTag Or ControlTag = vbNullString Then
enabled = True
Else
enabled = False
End If
End Sub

'Callback for chkToggle1 getPressed
Sub GetPressed(control As IRibbonControl, ByRef returnedVal)
If ControlTag = control.Tag Then
returnedVal = True
Else
returnedVal = False
End If
End Sub

'Callback for chkToggle1 onAction
Sub tgl_ClickAddin(control As IRibbonControl, pressed As Boolean)
If ControlTag = control.Tag Then
ControlTag = vbNullString
Else
ControlTag = control.Tag
End If
RefreshRibbon
End Sub
'Callback for chkToggle1 getLabel
Sub onGetLabel(control As IRibbonControl, ByRef returnedVal)
End Sub

'Callback for chkToggle1 getScreentip
Sub onGetScreentip(control As IRibbonControl, ByRef returnedVal)
End Sub

'Callback for chkToggle1 getSupertip
Sub onGetSupertip(control As IRibbonControl, ByRef returnedVal)
End Sub


Giving the result



enter image description here






share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53222207%2fexcel-custom-ribbon-toggle-button-dependency%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote



    accepted










    In my XML for the workbook I've got:



    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad = "RibbonOnLoad">
    <ribbon>
    <tabs>
    <tab id="customTab" label="Contoso" insertAfterMso="TabHome">
    <group id="customGroup" label="Contoso Tools">
    <checkBox id="chkToggle1" tag="chkToggle1" getLabel="onGetLabel" getScreentip="onGetScreentip" getSupertip="onGetSupertip" getPressed="GetPressed" onAction="tgl_ClickAddin" getEnabled="GetEnabled" />
    <checkBox id="chkToggle2" tag="chkToggle2" getLabel="onGetLabel" getScreentip="onGetScreentip" getSupertip="onGetSupertip" getPressed="GetPressed" onAction="tgl_ClickAddin" getEnabled="GetEnabled" />
    </group>
    </tab>
    </tabs>
    </ribbon>
    </customUI>


    I've Added a Sheet to my workbook called RibbonReference (Which I'd recommend setting .Visible = xlSheetVeryHidden) and then added the following to a Module:



    Option Explicit
    Dim rib As IRibbonUI
    Public ControlTag As String

    Private Declare Function ShellExecute _
    Lib "shell32.dll" Alias "ShellExecuteA" ( _
    ByVal hWnd As Long, _
    ByVal Operation As String, _
    ByVal Filename As String, _
    Optional ByVal Parameters As String, _
    Optional ByVal Directory As String, _
    Optional ByVal WindowStyle As Long = vbMinimizedFocus _
    ) As Long

    #If VBA7 Then
    Public Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)
    #Else
    Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)
    #End If
    #If VBA7 Then
    Function GetRibbon(ByVal lRibbonPointer As LongPtr) As Object
    #Else
    Function GetRibbon(ByVal lRibbonPointer As Long) As Object
    #End If
    Dim objRibbon As Object
    CopyMemory objRibbon, lRibbonPointer, LenB(lRibbonPointer)
    Set GetRibbon = objRibbon
    Set objRibbon = Nothing
    End Function
    Public Sub RefreshRibbon()
    If rib Is Nothing Then
    Set rib = GetRibbon(ThisWorkbook.Sheets("RibbonReference").Cells(2, 1).Value)
    Else
    rib.Invalidate
    End If
    End Sub
    Sub RibbonOnLoad(ribbon As IRibbonUI)
    Set rib = ribbon
    Debug.Print "ribbon:-", ObjPtr(ribbon)
    ThisWorkbook.Sheets("RibbonReference").Cells(2, 1).Value = ObjPtr(ribbon)
    End Sub
    Sub GetEnabled(control As IRibbonControl, ByRef enabled)
    If control.Tag = ControlTag Or ControlTag = vbNullString Then
    enabled = True
    Else
    enabled = False
    End If
    End Sub

    'Callback for chkToggle1 getPressed
    Sub GetPressed(control As IRibbonControl, ByRef returnedVal)
    If ControlTag = control.Tag Then
    returnedVal = True
    Else
    returnedVal = False
    End If
    End Sub

    'Callback for chkToggle1 onAction
    Sub tgl_ClickAddin(control As IRibbonControl, pressed As Boolean)
    If ControlTag = control.Tag Then
    ControlTag = vbNullString
    Else
    ControlTag = control.Tag
    End If
    RefreshRibbon
    End Sub
    'Callback for chkToggle1 getLabel
    Sub onGetLabel(control As IRibbonControl, ByRef returnedVal)
    End Sub

    'Callback for chkToggle1 getScreentip
    Sub onGetScreentip(control As IRibbonControl, ByRef returnedVal)
    End Sub

    'Callback for chkToggle1 getSupertip
    Sub onGetSupertip(control As IRibbonControl, ByRef returnedVal)
    End Sub


    Giving the result



    enter image description here






    share|improve this answer


























      up vote
      2
      down vote



      accepted










      In my XML for the workbook I've got:



      <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad = "RibbonOnLoad">
      <ribbon>
      <tabs>
      <tab id="customTab" label="Contoso" insertAfterMso="TabHome">
      <group id="customGroup" label="Contoso Tools">
      <checkBox id="chkToggle1" tag="chkToggle1" getLabel="onGetLabel" getScreentip="onGetScreentip" getSupertip="onGetSupertip" getPressed="GetPressed" onAction="tgl_ClickAddin" getEnabled="GetEnabled" />
      <checkBox id="chkToggle2" tag="chkToggle2" getLabel="onGetLabel" getScreentip="onGetScreentip" getSupertip="onGetSupertip" getPressed="GetPressed" onAction="tgl_ClickAddin" getEnabled="GetEnabled" />
      </group>
      </tab>
      </tabs>
      </ribbon>
      </customUI>


      I've Added a Sheet to my workbook called RibbonReference (Which I'd recommend setting .Visible = xlSheetVeryHidden) and then added the following to a Module:



      Option Explicit
      Dim rib As IRibbonUI
      Public ControlTag As String

      Private Declare Function ShellExecute _
      Lib "shell32.dll" Alias "ShellExecuteA" ( _
      ByVal hWnd As Long, _
      ByVal Operation As String, _
      ByVal Filename As String, _
      Optional ByVal Parameters As String, _
      Optional ByVal Directory As String, _
      Optional ByVal WindowStyle As Long = vbMinimizedFocus _
      ) As Long

      #If VBA7 Then
      Public Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)
      #Else
      Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)
      #End If
      #If VBA7 Then
      Function GetRibbon(ByVal lRibbonPointer As LongPtr) As Object
      #Else
      Function GetRibbon(ByVal lRibbonPointer As Long) As Object
      #End If
      Dim objRibbon As Object
      CopyMemory objRibbon, lRibbonPointer, LenB(lRibbonPointer)
      Set GetRibbon = objRibbon
      Set objRibbon = Nothing
      End Function
      Public Sub RefreshRibbon()
      If rib Is Nothing Then
      Set rib = GetRibbon(ThisWorkbook.Sheets("RibbonReference").Cells(2, 1).Value)
      Else
      rib.Invalidate
      End If
      End Sub
      Sub RibbonOnLoad(ribbon As IRibbonUI)
      Set rib = ribbon
      Debug.Print "ribbon:-", ObjPtr(ribbon)
      ThisWorkbook.Sheets("RibbonReference").Cells(2, 1).Value = ObjPtr(ribbon)
      End Sub
      Sub GetEnabled(control As IRibbonControl, ByRef enabled)
      If control.Tag = ControlTag Or ControlTag = vbNullString Then
      enabled = True
      Else
      enabled = False
      End If
      End Sub

      'Callback for chkToggle1 getPressed
      Sub GetPressed(control As IRibbonControl, ByRef returnedVal)
      If ControlTag = control.Tag Then
      returnedVal = True
      Else
      returnedVal = False
      End If
      End Sub

      'Callback for chkToggle1 onAction
      Sub tgl_ClickAddin(control As IRibbonControl, pressed As Boolean)
      If ControlTag = control.Tag Then
      ControlTag = vbNullString
      Else
      ControlTag = control.Tag
      End If
      RefreshRibbon
      End Sub
      'Callback for chkToggle1 getLabel
      Sub onGetLabel(control As IRibbonControl, ByRef returnedVal)
      End Sub

      'Callback for chkToggle1 getScreentip
      Sub onGetScreentip(control As IRibbonControl, ByRef returnedVal)
      End Sub

      'Callback for chkToggle1 getSupertip
      Sub onGetSupertip(control As IRibbonControl, ByRef returnedVal)
      End Sub


      Giving the result



      enter image description here






      share|improve this answer
























        up vote
        2
        down vote



        accepted







        up vote
        2
        down vote



        accepted






        In my XML for the workbook I've got:



        <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad = "RibbonOnLoad">
        <ribbon>
        <tabs>
        <tab id="customTab" label="Contoso" insertAfterMso="TabHome">
        <group id="customGroup" label="Contoso Tools">
        <checkBox id="chkToggle1" tag="chkToggle1" getLabel="onGetLabel" getScreentip="onGetScreentip" getSupertip="onGetSupertip" getPressed="GetPressed" onAction="tgl_ClickAddin" getEnabled="GetEnabled" />
        <checkBox id="chkToggle2" tag="chkToggle2" getLabel="onGetLabel" getScreentip="onGetScreentip" getSupertip="onGetSupertip" getPressed="GetPressed" onAction="tgl_ClickAddin" getEnabled="GetEnabled" />
        </group>
        </tab>
        </tabs>
        </ribbon>
        </customUI>


        I've Added a Sheet to my workbook called RibbonReference (Which I'd recommend setting .Visible = xlSheetVeryHidden) and then added the following to a Module:



        Option Explicit
        Dim rib As IRibbonUI
        Public ControlTag As String

        Private Declare Function ShellExecute _
        Lib "shell32.dll" Alias "ShellExecuteA" ( _
        ByVal hWnd As Long, _
        ByVal Operation As String, _
        ByVal Filename As String, _
        Optional ByVal Parameters As String, _
        Optional ByVal Directory As String, _
        Optional ByVal WindowStyle As Long = vbMinimizedFocus _
        ) As Long

        #If VBA7 Then
        Public Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)
        #Else
        Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)
        #End If
        #If VBA7 Then
        Function GetRibbon(ByVal lRibbonPointer As LongPtr) As Object
        #Else
        Function GetRibbon(ByVal lRibbonPointer As Long) As Object
        #End If
        Dim objRibbon As Object
        CopyMemory objRibbon, lRibbonPointer, LenB(lRibbonPointer)
        Set GetRibbon = objRibbon
        Set objRibbon = Nothing
        End Function
        Public Sub RefreshRibbon()
        If rib Is Nothing Then
        Set rib = GetRibbon(ThisWorkbook.Sheets("RibbonReference").Cells(2, 1).Value)
        Else
        rib.Invalidate
        End If
        End Sub
        Sub RibbonOnLoad(ribbon As IRibbonUI)
        Set rib = ribbon
        Debug.Print "ribbon:-", ObjPtr(ribbon)
        ThisWorkbook.Sheets("RibbonReference").Cells(2, 1).Value = ObjPtr(ribbon)
        End Sub
        Sub GetEnabled(control As IRibbonControl, ByRef enabled)
        If control.Tag = ControlTag Or ControlTag = vbNullString Then
        enabled = True
        Else
        enabled = False
        End If
        End Sub

        'Callback for chkToggle1 getPressed
        Sub GetPressed(control As IRibbonControl, ByRef returnedVal)
        If ControlTag = control.Tag Then
        returnedVal = True
        Else
        returnedVal = False
        End If
        End Sub

        'Callback for chkToggle1 onAction
        Sub tgl_ClickAddin(control As IRibbonControl, pressed As Boolean)
        If ControlTag = control.Tag Then
        ControlTag = vbNullString
        Else
        ControlTag = control.Tag
        End If
        RefreshRibbon
        End Sub
        'Callback for chkToggle1 getLabel
        Sub onGetLabel(control As IRibbonControl, ByRef returnedVal)
        End Sub

        'Callback for chkToggle1 getScreentip
        Sub onGetScreentip(control As IRibbonControl, ByRef returnedVal)
        End Sub

        'Callback for chkToggle1 getSupertip
        Sub onGetSupertip(control As IRibbonControl, ByRef returnedVal)
        End Sub


        Giving the result



        enter image description here






        share|improve this answer














        In my XML for the workbook I've got:



        <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad = "RibbonOnLoad">
        <ribbon>
        <tabs>
        <tab id="customTab" label="Contoso" insertAfterMso="TabHome">
        <group id="customGroup" label="Contoso Tools">
        <checkBox id="chkToggle1" tag="chkToggle1" getLabel="onGetLabel" getScreentip="onGetScreentip" getSupertip="onGetSupertip" getPressed="GetPressed" onAction="tgl_ClickAddin" getEnabled="GetEnabled" />
        <checkBox id="chkToggle2" tag="chkToggle2" getLabel="onGetLabel" getScreentip="onGetScreentip" getSupertip="onGetSupertip" getPressed="GetPressed" onAction="tgl_ClickAddin" getEnabled="GetEnabled" />
        </group>
        </tab>
        </tabs>
        </ribbon>
        </customUI>


        I've Added a Sheet to my workbook called RibbonReference (Which I'd recommend setting .Visible = xlSheetVeryHidden) and then added the following to a Module:



        Option Explicit
        Dim rib As IRibbonUI
        Public ControlTag As String

        Private Declare Function ShellExecute _
        Lib "shell32.dll" Alias "ShellExecuteA" ( _
        ByVal hWnd As Long, _
        ByVal Operation As String, _
        ByVal Filename As String, _
        Optional ByVal Parameters As String, _
        Optional ByVal Directory As String, _
        Optional ByVal WindowStyle As Long = vbMinimizedFocus _
        ) As Long

        #If VBA7 Then
        Public Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)
        #Else
        Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)
        #End If
        #If VBA7 Then
        Function GetRibbon(ByVal lRibbonPointer As LongPtr) As Object
        #Else
        Function GetRibbon(ByVal lRibbonPointer As Long) As Object
        #End If
        Dim objRibbon As Object
        CopyMemory objRibbon, lRibbonPointer, LenB(lRibbonPointer)
        Set GetRibbon = objRibbon
        Set objRibbon = Nothing
        End Function
        Public Sub RefreshRibbon()
        If rib Is Nothing Then
        Set rib = GetRibbon(ThisWorkbook.Sheets("RibbonReference").Cells(2, 1).Value)
        Else
        rib.Invalidate
        End If
        End Sub
        Sub RibbonOnLoad(ribbon As IRibbonUI)
        Set rib = ribbon
        Debug.Print "ribbon:-", ObjPtr(ribbon)
        ThisWorkbook.Sheets("RibbonReference").Cells(2, 1).Value = ObjPtr(ribbon)
        End Sub
        Sub GetEnabled(control As IRibbonControl, ByRef enabled)
        If control.Tag = ControlTag Or ControlTag = vbNullString Then
        enabled = True
        Else
        enabled = False
        End If
        End Sub

        'Callback for chkToggle1 getPressed
        Sub GetPressed(control As IRibbonControl, ByRef returnedVal)
        If ControlTag = control.Tag Then
        returnedVal = True
        Else
        returnedVal = False
        End If
        End Sub

        'Callback for chkToggle1 onAction
        Sub tgl_ClickAddin(control As IRibbonControl, pressed As Boolean)
        If ControlTag = control.Tag Then
        ControlTag = vbNullString
        Else
        ControlTag = control.Tag
        End If
        RefreshRibbon
        End Sub
        'Callback for chkToggle1 getLabel
        Sub onGetLabel(control As IRibbonControl, ByRef returnedVal)
        End Sub

        'Callback for chkToggle1 getScreentip
        Sub onGetScreentip(control As IRibbonControl, ByRef returnedVal)
        End Sub

        'Callback for chkToggle1 getSupertip
        Sub onGetSupertip(control As IRibbonControl, ByRef returnedVal)
        End Sub


        Giving the result



        enter image description here







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 9 at 14:07

























        answered Nov 9 at 14:02









        Tom

        5,58211641




        5,58211641



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53222207%2fexcel-custom-ribbon-toggle-button-dependency%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

            Crossroads (UK TV series)

            ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế