Modifying the custom ribbon with VBA

Damian86

New Member
Joined
Jun 30, 2014
Messages
47
Hi,

I have a custom ribbon with controls that I have tags associated to. I can change visibility of groups and controls by changing the tag property:
Code:
Call RefreshRibbon(Tag:="MyGroup1")

I was wondering if there is a possibility of making the same by not changing the tag property, but directly addressing a control and modifying its properties.

Can you help me?
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Afraid not, you have to use callbacks to set the visibility of controls on the Ribbon.
 
Last edited:
Upvote 0
Thanks RoryA.

But is there a way to use a callback without referring to the "tag" property? I would like to refer to a label, for example. Is there such possibility?
 
Upvote 0
You can invalidate a control specifically by its id using the Ribbon object's InvalidateControl method.
 
Upvote 0
Could you please provide me with the code?

Now I use:
Code:
Option Explicit
Dim Rib As IRibbonUI
Public MyTag As String

Sub Ribbon******(ribbon As IRibbonUI)
    Set Rib = ribbon
End Sub

Sub GetVisible(Control As IRibbonControl, ByRef visible)
    
    If MyTag = "MyTag" Then
    visible = True
    Else
    If Control.Tag Like MyTag Then
    visible = True
    Else
    visible = False
    End If
    End If
    
End Sub

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

How can I relate to its ID?
 
Upvote 0
You'd pass the ID as a string instead of the tag. How would you determine whether to show or hide the control?
 
Upvote 0
Thanks RoryA. Maybe I wasn't clear enough from the beginning.

When I use...
Code:
Call RefreshRibbon(Tag:="MyGroup1*")
...for example I get all tags like MyGroup1, MyGroup15, MyGroup125 etc. visible or hidden. What I would like to do is to address a specific control, let's say by referring to it's tag. When I use...
Code:
Call RefreshRibbon(Tag:="MyGroup125")
... I get the MyGroup125 visible, but all other groups are hidden. I would like to manipulate a single control by referring to a tag or id. Tags, the way I use them, work globally, so when I update the ribbon, it shows/hides controls referring to a tag I set up.
I would like to do something like:
Code:
If Control.Tag Like "Group125" Then
visible = false
End If
... so that only one control tagged as "Group125" would be modified.

I hope I was clear enough :)
 
Upvote 0
If I understand you correctly, you could do something like this:

Code:
Sub RefreshRibbon(Tag As String, Optional ID as string = vbNullString)
    MyTag = Tag
    If Rib Is Nothing Then
        MsgBox "Error, Save/Restart your workbook"
    Else
       if ID = vbNullstring then
        Rib.Invalidate
       else
        Rib.InvalidateControl ID
       end if
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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