VBA Enable multiple Ribbon buttons

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, When invalidating the Ribbon control is there a way to enable multiple buttons from different groups on the ribbon?

I have followed Ron de Bruins example and have managed to make a group of buttons enable/disable based on column selection however I wish to add more buttons under this condition from another group of buttons on the same ribbon.

Code below uses the Tag for Group1 set of buttons but say if I wanted to Enable Group1, Group2 Button2, Group4 and Group5 button1 How can I invalidate the controls for these. Can someone help please

VBA Code:
Sub MyEnableGroup1()
    Call RefreshRibbon(Tag:="Group1*")
End Sub

Sub RefreshRibbon(Tag As String)
    MyTag = Tag
    If iRib Is Nothing Then
        MsgBox "Error, Save/Restart your workbook"
    Else
        iRib.Invalidate
    End If
End Sub

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

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
in the XML ribbon structure each button myst have a getenabled callback assigned.
The same you did for groups, you must do for buttons as well.
All buttons that will have a change of state must have getenabled.

There is a trick though. I haven't tested it but I believe I am right: you cannot enable a button if it's parent group is disabled. :)
Does it make sense?
 
Upvote 0

Forum statistics

Threads
1,215,004
Messages
6,122,659
Members
449,091
Latest member
peppernaut

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