Link to home
Start Free TrialLog in
Avatar of 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="">
<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" />

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

Open in new window

Please help.
Avatar of GunterAv
Flag of Germany image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Fi69


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.