Home > OS >  Word ribbon ignores insertAfterMso
Word ribbon ignores insertAfterMso

Time:12-06

I have a ribbon that I need to position after the HomeTab (or any other built-in tab) in Word. But Word seems to ignore the insertAfterMso (and insertBeforeMso) attributes.

I tried using insertAfterQ/insertBeforeQ as well, but I can't get those to work with the built-in tabs.

Snippet of the ribbon XML:

  <customUI 
      onLoad="Ribbon_Load" xmlns="http://schemas.microsoft.com/office/2006/01/customui"  
      xmlns:cstm1="myns"
      xmlns:cstm2="myns2">
  <ribbon>
    <tabs>
      <tab 
          idQ="cstm1:MyCustomTab" 
          label="My Custom Tab"
          getVisible="MyCustomTab_getVisible"
          insertAfterMso="HomeTab">
    </tabs>
  </ribbon>
</customUI>

I suspect it might be related to the use of the idQ attribute, but I need that feature, so I can't remove it :-/

Note that the tab is displayed on the Office ribbon, but it's at the far right end of the ribbon, as it would be without the insertAfterMso attribute added.

CodePudding user response:

There is no such attribute for the customUI element in the ribbon XML. Instead, you need to specify the insertAfterMso attribute for your custom tab element:

<customUI onLoad="Ribbon_Load" 
      xmlns="http://schemas.microsoft.com/office/2006/01/customui"  
      xmlns:cstm1="myns"
      xmlns:cstm2="myns2">
  <ribbon>
    <tabs>
      <tab id="myCustomTab"
           insertAfterMso="HomeTab"
           label="My Custom Tab"
           getVisible="MyCustomTab_getVisible">
    </tabs>
  </ribbon>
</customUI>

By default, if a VSTO Add-in attempts to manipulate the Microsoft Office user interface (UI) and fails, no error message is displayed. However, you can configure Microsoft Office applications to display messages for errors that relate to the UI. You can use these messages to help determine why a custom ribbon does not appear, or why a ribbon appears but no controls appear. See How to: Show Add-in user interface errors.

CodePudding user response:

The reason to use the idQ attribute to identify the tab, instead of the regular id attribute, is when more than one VSTO AddIn needs to modify the content of a specific tab.

It turns out that if you want control the position of the tab, by using the insertAfterMso or insertBeforeMso attributes, you need to do so in all AddIns modifying the target tab - adding that attribute to just one of the AddIns is not enough.

So my markup was correct - but it was being "sabotaged" by my secondary VSTO AddIn.

This was solved by Trial & Error, I haven't been able to find any documentation stating this requirement.

  • Related