troubleshooting Question

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

Avatar of Fi69
Fi69 asked on
Visual Basic ClassicMicrosoft Word
2 Comments1 Solution2617 ViewsLast Modified:
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="">
<ribbon startFromScratch="false">
<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" />

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"
    End If
End Sub

Please help.

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros