Avatar of Fi69
Fi69
 asked on

Custom UI Editor Word VBA to change tab label on the fly

Hi experts

I need to be able to change the name of the custom tab on my ribbon on the fly. I've used the Custom UI Editor for Microsoft Office to customise the ribbon.

I have a tab called eg "Tab A". Depending on a users selection, I want to rename the tab to "Tab B" or "Tab C", etc. I can only get it to work when the document is re-opened. I need it to refresh without closing and reopening, ie on the fly. I found some code at Ron de Bruin’s Web site to refresh, but I can't get it to work.

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
<ribbon startFromScratch="false">
 <tabs>
<tab id="MyTools" getLabel="RibbonControls.getLabel" insertBeforeMso="TabHome" keytip="Q">
<group id="customGroup" label="General">
<button id="button1" label="Button 1" mageMso="ViewsFormView" size="large" onAction="RibbonControls.Macro1" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>

Open in new window


And here's my vba code.

Option Explicit
Public myRibbon As IRibbonUI
Public myTag As String

Sub RibbonLoaded(ribbon As IRibbonUI)
	Set myRibbon = ribbon
End Sub

Sub GetLabel(control As IRibbonControl, ByRef myLabel)
    Dim strLabel As String
    strLabel = activedocument.Variables("RibbonLabel").Value
    Select Case control.ID
        Case "MyTools"
            myLabel = strLabel
        Case Else
            myLabel = "PB"
    End Select
End Sub

Sub testrefresh()
    RefreshRibbon ("Tab*")
End Sub

Sub RefreshRibbon(tag As String)
    myTag = tag
    If myRibbon Is Nothing Then   '''''''''IT ERRORS HERE 
        MsgBox "Error"
    Else
        myRibbon.Invalidate
    End If
End Sub

Open in new window


Please help.
Visual Basic ClassicMicrosoft Word

Avatar of undefined
Last Comment
Fi69

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
GunterAv

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Fi69

ASKER
That worked. I saw the load code in my vb project but didn't think to check it was in the ribbon XML! I'm annoyed with myself!

Thanks for your help.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck