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

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

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Hello,

you need an onLoad in your Ribbon XML

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="RibbonLoaded">

Open in new window


See also:
http://www.accessribbon.de/en/?Access_-_Ribbons:Callbacks:customUI_-_onLoad

and:
http://www.accessribbon.de/en/?Access_-_Ribbons:Update_Ribbons_Dynamically

Author

Commented:
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