none
Ribbon XML - custom ribbon tab appears twice RRS feed

  • Question

  • I have built a template for a client that contains a custom ribbon tab, and it works great. 

    We don't create new documents using the File New method with this template, because we discovered that then the document also contains a copy of the ribbon XML, and if any change is made to the ribbon XML in the template, the custom ribbon tab appears twice. So, we attach the template to documents that require this tab. That way  the ribbon XML lives in the template, and loads whenever a document is opened that is attached to it.

    Now we have found that some users need to use these documents offline, where they don't have access to the template. 

    Here is my question:

    Is there a way to tell Word to ignore the ribbon XML in the document if the template contains XML for a ribbon tab with the same name? 

    We are using Word 2010.

    Thanks.

    Thursday, December 13, 2012 7:33 PM

Answers

  • Hi BloomHaven,

    Thank you for posting in the MSDN Forum.

    I've tried to reproduce your scenario by steps below:

    • Create a Word template project with Ribbon XML ribbon tabs.
    • Startup Word application, Ctrl+w to shutdown the current document. Now the word application have no documents opened.
    • Drag the template into Word application. Now you have the template opened.
    • Go to "File" Tab or rather backstage, then New->New from existing. 
    • Go to the project folder, again choose the template file.

    Now I have a doc with 2 same tabs just as you've described.

    I solve this issue by using idQ property seen in Customizing the 2007 Office Fluent Ribbon for Developers (Part 3 of 3).

    In that page, you'll see XML file like the below which means you'll need to add your own namespace.

    <customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" 
      xmlns:x="myNameSpace" >
      <ribbon>
        <tabs>
          <tab idMso="TabAddIns">
            <group idQ="x:Contoso" label="Contoso">
              <button id="C1" label="Contoso Button 1" size="large" 
                imageMso="FileSave" onAction="c_action1" />
            </group>
          </tab>
        </tabs>
      </ribbon>
    </customUI>

    Then I create my Ribbon XML file like this

      <ribbon>
        <tabs>
          <tab idQ="x:MyTab" label ="MyTab">
            <group id="MyGroup" label="My Group">
              <button id ="button1" label ="button1"/>
            </group>
          </tab>
        </tabs>
      </ribbon>

    Just the same as I guessed, I got only one "MyTab" but two groups with "button1".

    Then I adapted my Ribbon XML code into below.

      <ribbon>
        <tabs>
          <tab idQ="x:MyTab" label ="MyTab">
            <group idQ="x:MyGroup" label="My Group">
              <button idQ ="x:button1" label ="button1"/>
            </group>
          </tab>
        </tabs>
      </ribbon>

    This time the code works fine. You can take a try and let me know the results.

    Hope it helps.


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, December 14, 2012 12:09 PM
    Moderator

All replies

  • Hi BloomHaven,

    Thank you for posting in the MSDN Forum.

    I've tried to reproduce your scenario by steps below:

    • Create a Word template project with Ribbon XML ribbon tabs.
    • Startup Word application, Ctrl+w to shutdown the current document. Now the word application have no documents opened.
    • Drag the template into Word application. Now you have the template opened.
    • Go to "File" Tab or rather backstage, then New->New from existing. 
    • Go to the project folder, again choose the template file.

    Now I have a doc with 2 same tabs just as you've described.

    I solve this issue by using idQ property seen in Customizing the 2007 Office Fluent Ribbon for Developers (Part 3 of 3).

    In that page, you'll see XML file like the below which means you'll need to add your own namespace.

    <customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" 
      xmlns:x="myNameSpace" >
      <ribbon>
        <tabs>
          <tab idMso="TabAddIns">
            <group idQ="x:Contoso" label="Contoso">
              <button id="C1" label="Contoso Button 1" size="large" 
                imageMso="FileSave" onAction="c_action1" />
            </group>
          </tab>
        </tabs>
      </ribbon>
    </customUI>

    Then I create my Ribbon XML file like this

      <ribbon>
        <tabs>
          <tab idQ="x:MyTab" label ="MyTab">
            <group id="MyGroup" label="My Group">
              <button id ="button1" label ="button1"/>
            </group>
          </tab>
        </tabs>
      </ribbon>

    Just the same as I guessed, I got only one "MyTab" but two groups with "button1".

    Then I adapted my Ribbon XML code into below.

      <ribbon>
        <tabs>
          <tab idQ="x:MyTab" label ="MyTab">
            <group idQ="x:MyGroup" label="My Group">
              <button idQ ="x:button1" label ="button1"/>
            </group>
          </tab>
        </tabs>
      </ribbon>

    This time the code works fine. You can take a try and let me know the results.

    Hope it helps.


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, December 14, 2012 12:09 PM
    Moderator
  • I have the same problem the custom ribbon is appearing twice when the document is created  from template. as advised i have defined IDQ and now the dynamic menu is appraing wtice. Please refer my code below. When I add idQ to dynamic menu, then the Menu items are not getting displayed. Please advice how to get rid of the duplication

    <

    customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui"xmlns:x="myNameSpace"


    >

    <

    ribbon startFromScratch="false">

    <

    tabs>

    <

    tab idMso="TabAddIns"label="Template Functions">

    <

    group idQ="x:customGroup"label="Template Functions">

    <

    dynamicMenu id="dmnu1"label="Template Menu"getContent="onGetContent"invalidateContentOnDrop="false"size="normal"/>

    </

    group>

    </

    tab>

    </

    tabs>

    </

    ribbon>

    </

    customUI>

    Friday, February 28, 2014 6:10 PM