VBA UI Ribbon Toggle Button

decadence

Well-known Member
Joined
Oct 9, 2015
Messages
525
Office Version
  1. 365
  2. 2016
  3. 2013
  4. 2010
  5. 2007
Platform
  1. Windows
Hi, I have created a toggle button in xml which works ok but what I would like to do is enable two other buttons on the ribbon If toggle button is pressed and disable the same two buttons when toggle is un pressed. Can some one help with this please?
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Hi Worf, I have been using this as a reference however this is only a example, I have incorporated the example into my own ribbon. but there isn't much help on how to be more dynamic with buttons.
 
Upvote 0
I understand you are not able to accomplish what is described at post #1 . I will try to do it.
 
Upvote 0
This example shows how to use a Ribbon toggle button to enable or disable two other Ribbon controls. Tell me if you need the test workbook.

zdc2x8E.png



Code:
Dim myRibbon As IRibbonUI, PressedState As Boolean
Public MyTag$


Sub GE(control As IRibbonControl, ByRef Enabled)
    If MyTag = "Enable" Then
        Enabled = True
    Else
        If control.Tag Like MyTag Then
            Enabled = True
        Else
            Enabled = False
        End If
    End If
End Sub


Sub RefreshRibbon(Tag$)
MyTag = Tag
If myRibbon Is Nothing Then
    MsgBox "Error, Save/Restart your workbook" & vbNewLine & _
    "Visit this page for a solution: http://www.rondebruin.nl/ribbonstate.htm"
Else
    myRibbon.Invalidate
End If
End Sub


Sub Ribb******ed(ribbon As IRibbonUI)
    Set myRibbon = ribbon
    PressedState = False
End Sub


Sub Macro1(control As IRibbonControl, pressed As Boolean)
    Select Case pressed
    Case True
        PressedState = True
        RefreshRibbon "*"
    Case False
        PressedState = False
        RefreshRibbon "ToggleButton1"
    End Select
    myRibbon.InvalidateControl "ToggleButton1"
    myRibbon.InvalidateControl "G1B1"
    myRibbon.InvalidateControl "G1B2"
End Sub


Sub GetImage(control As IRibbonControl, ByRef image)
    Select Case control.ID
    Case "ToggleButton1"
        Select Case PressedState
        Case True: image = "HappyFace"
        Case False: image = "SadFace"
        End Select
    End Select
End Sub


Sub GetLabel(ByVal control As IRibbonControl, ByRef label)
    Select Case control.ID
    Case "ToggleButton1"
        Select Case PressedState
        Case True: label = "Happy"
        Case False: label = "Sad"
        End Select
    End Select
End Sub
 
Upvote 0
This example shows how to use a Ribbon toggle button to enable or disable two other Ribbon controls. Tell me if you need the test workbook.

zdc2x8E.png



Code:
Dim myRibbon As IRibbonUI, PressedState As Boolean
Public MyTag$


Sub GE(control As IRibbonControl, ByRef Enabled)
    If MyTag = "Enable" Then
        Enabled = True
    Else
        If control.Tag Like MyTag Then
            Enabled = True
        Else
            Enabled = False
        End If
    End If
End Sub


Sub RefreshRibbon(Tag$)
MyTag = Tag
If myRibbon Is Nothing Then
    MsgBox "Error, Save/Restart your workbook" & vbNewLine & _
    "Visit this page for a solution: http://www.rondebruin.nl/ribbonstate.htm"
Else
    myRibbon.Invalidate
End If
End Sub


Sub Ribb******ed(ribbon As IRibbonUI)
    Set myRibbon = ribbon
    PressedState = False
End Sub


Sub Macro1(control As IRibbonControl, pressed As Boolean)
    Select Case pressed
    Case True
        PressedState = True
        RefreshRibbon "*"
    Case False
        PressedState = False
        RefreshRibbon "ToggleButton1"
    End Select
    myRibbon.InvalidateControl "ToggleButton1"
    myRibbon.InvalidateControl "G1B1"
    myRibbon.InvalidateControl "G1B2"
End Sub


Sub GetImage(control As IRibbonControl, ByRef image)
    Select Case control.ID
    Case "ToggleButton1"
        Select Case PressedState
        Case True: image = "HappyFace"
        Case False: image = "SadFace"
        End Select
    End Select
End Sub


Sub GetLabel(ByVal control As IRibbonControl, ByRef label)
    Select Case control.ID
    Case "ToggleButton1"
        Select Case PressedState
        Case True: label = "Happy"
        Case False: label = "Sad"
        End Select
    End Select
End Sub

Hello Worf,

I am working on something similar.

Please send me a copy of this workbook.

The XML code is too small to read.

Thanks,

Kurt
 
Upvote 0

Forum statistics

Threads
1,223,162
Messages
6,170,432
Members
452,326
Latest member
johnshaji

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