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

Fi69 used Ask the Experts™
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.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

you need an onLoad in your Ribbon XML

<customUI xmlns="" onLoad="RibbonLoaded">

Open in new window

See also:



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.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial