I have experienced the following situation in two totally different Windows environments (home and work) on Office 365 (Word 11929.20254) and Word 2016, using a range of documents and templates which use VBA and customUI.xml to display a custom ribbon:
- I open any Word document (an existing one or a new blank document based on Normal.dotm).
- I open another Word document, which has a custom ribbon (customUI.xml); basic example below.
- I close the document with the custom ribbon.
- I reopen the document with the custom ribbon.
- Several things are wrong with the custom ribbon at this point (no VBA errors occur). Even if the first tab on the ribbon of the second document belongs to the custom ribbon (ie it precedes the Home tab), it will not activate. The onLoad callback does not run. This is remedied only by clicking the custom ribbon tab, at which point it springs into life (and runs onLoad), or by closing all Word documents and reopening.
If I run the above situation in Excel or PowerPoint with spreadsheet or presentation files with the exact same custom ribbon as I used in Word above, step 5 doesn't apply; the ribbon works properly, onLoad runs, and so on.
Why does the Word ribbon appear to be deficient in a way in which other Office ribbons are not? Would developing an add-in rather than VBA and customUI.xml resolve or bypass this issue?
Edit:
A bare example of a custom ribbon and associated VBA follows. Put these in the customUI.xml and VBA of a Word document and use this as the second Word document, mentioned in steps 2 to 5.
Put the ribbon and VBA below into an Excel spreadsheet then run through steps 1 to 5 above, except using Excel spreadsheets instead of Word documents. Upon reaching step 5, the ribbon seems fine, unlike in Word.
customUI.xml:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="modRibbon.CustomUI_OnLoad">
<ribbon>
<tabs>
<tab id="tabCustom" label="Custom" insertBeforeMso="TabHome">
<group id="grpCustom1" imageMso="EditDocument" label="Custom group 1">
<button id="btnA" size="large" label="Aa" imageMso="EditDocument" onAction="modRibbon.btn1A_OnAction" screentip="Aa" supertip="A button."/>
</group>
<group id="grpCustom2" imageMso="EditBusinessCard" label="Custom group 2">
<button id="btnB" size="large" label="Bb" imageMso="EditBusinessCard" onAction="modRibbon.btn2B_OnAction" screentip="Bb" supertip="Another button."/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>
modRibbon VBA module:
'Callback for customUI.onLoad
Sub CustomUI_OnLoad(ribbon As IRibbonUI)
End Sub
'Callback for btnA_onAction
Sub btn1A_OnAction(control As IRibbonControl)
End Sub
'Callback for btnB_onAction
Sub btn2B_OnAction(control As IRibbonControl)
End Sub