none
How to import the customized ribbon to Word without overwriting the existing ribbon? RRS feed

Answers

  • HI SaraSh,

    Based on my understanding, you want to import the customized ribbon without overwriting the existing ribbon.

    As far as I know,we can use OpenXml to Operate CustiomUI.xml to add ribbon.

    The basic structure of customUI.xml is the following code:

    <customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
      <ribbon>
    	<tabs>
    	  <tab id="XXX" label="XXX">
    		<group id="XXX" label="XXX">
    		  <button id="XXX" label="XXX" />
    		</group>
    	  </tab>
    	</tabs>
      </ribbon>
    </customUI>

    You can see customUI.xml using Custom UI Editor Tool or Rename New Tab.docx to New Tab.docx.zip.

    we can get customized ribbon Xml file,add ribbon tab in the existing ribbon customized Xml file

    #Step1 Get you customized ribbon Xml file,

    using DocumentFormat.OpenXml.Office.CustomUI;
    using DocumentFormat.OpenXml.Packaging;
    using DocumentFormat.OpenXml;
    using DocumentFormat.OpenXml.Wordprocessing;

              

     using (WordprocessingDocument doc =
            WordprocessingDocument.Open(fileName, true))
                {
                    var part = doc.RibbonExtensibilityPart;
                    if (part == null)
                    {
                        part = doc.AddRibbonExtensibilityPart();
                    }
                    string XmlString = part.CustomUI.InnerXml;

    #Step2 Operate Xml File

    #Step3 Save CunstomUI.xml

            private void fnAddRibbon(string v_strWordPath, string v_strCustomerXML)
            {
                using (WordprocessingDocument myDoc = WordprocessingDocument.Open(v_strWordPath, true))
                {
                    MainDocumentPart mainPart = myDoc.MainDocumentPart;
    
                    if (myDoc.GetPartsCountOfType<RibbonExtensibilityPart>() > 0)
                        myDoc.DeletePart(myDoc.GetPartsOfType<RibbonExtensibilityPart>().First());
    
                    RibbonExtensibilityPart ribbonExtensibilityPart = myDoc.AddNewPart<RibbonExtensibilityPart>();
                    ribbonExtensibilityPart.CustomUI = new DocumentFormat.OpenXml.Office.CustomUI.CustomUI(v_strCustomerXML);
                }
            }




    Thursday, September 19, 2013 9:01 AM
  • Hi Sarah

    The options availabe in Word's user interface for modifying the QAT and the Ribbon (not available in 2007) change the Ribbon for the entire interface and do replace what was originally there. These are meant for the user, not for individual documents.

    If you have a template and you want to share its customizations with other users, the better approach would probably be to save the template in the users' Startup folders. Where this is depends on 1) the version of Word and 2) whether a company has modified that location.

    Any template saved in this folder will automatically be loaded by Word as a "template add-in". All macros and Ribbon customizations, as well as building blocks and keyboard shortcuts, will be available at all times to the user. Yet what it provides will not interfere with the user's own customizations.


    Cindy Meister, VSTO/Word MVP, my blog

    Monday, September 30, 2013 6:18 PM
    Moderator

All replies

  • HI SaraSh,

    Based on my understanding, you want to import the customized ribbon without overwriting the existing ribbon.

    As far as I know,we can use OpenXml to Operate CustiomUI.xml to add ribbon.

    The basic structure of customUI.xml is the following code:

    <customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
      <ribbon>
    	<tabs>
    	  <tab id="XXX" label="XXX">
    		<group id="XXX" label="XXX">
    		  <button id="XXX" label="XXX" />
    		</group>
    	  </tab>
    	</tabs>
      </ribbon>
    </customUI>

    You can see customUI.xml using Custom UI Editor Tool or Rename New Tab.docx to New Tab.docx.zip.

    we can get customized ribbon Xml file,add ribbon tab in the existing ribbon customized Xml file

    #Step1 Get you customized ribbon Xml file,

    using DocumentFormat.OpenXml.Office.CustomUI;
    using DocumentFormat.OpenXml.Packaging;
    using DocumentFormat.OpenXml;
    using DocumentFormat.OpenXml.Wordprocessing;

              

     using (WordprocessingDocument doc =
            WordprocessingDocument.Open(fileName, true))
                {
                    var part = doc.RibbonExtensibilityPart;
                    if (part == null)
                    {
                        part = doc.AddRibbonExtensibilityPart();
                    }
                    string XmlString = part.CustomUI.InnerXml;

    #Step2 Operate Xml File

    #Step3 Save CunstomUI.xml

            private void fnAddRibbon(string v_strWordPath, string v_strCustomerXML)
            {
                using (WordprocessingDocument myDoc = WordprocessingDocument.Open(v_strWordPath, true))
                {
                    MainDocumentPart mainPart = myDoc.MainDocumentPart;
    
                    if (myDoc.GetPartsCountOfType<RibbonExtensibilityPart>() > 0)
                        myDoc.DeletePart(myDoc.GetPartsOfType<RibbonExtensibilityPart>().First());
    
                    RibbonExtensibilityPart ribbonExtensibilityPart = myDoc.AddNewPart<RibbonExtensibilityPart>();
                    ribbonExtensibilityPart.CustomUI = new DocumentFormat.OpenXml.Office.CustomUI.CustomUI(v_strCustomerXML);
                }
            }




    Thursday, September 19, 2013 9:01 AM
  • Hi,Mercop,

    Thanks for your quickly response,I will give it a try and let you know the results.

    Regards,

    Sarah

    Sunday, September 22, 2013 2:21 AM
  • Hi,Mercop,

    Thank you again for your step-by-step guide on this,I know little about C# so I am not sure if I understand you correctly.If you can provide the VB code it will make more sense to me.

    I got the customized Ribbon XML through renaming the Tab.dotm to Tab.dotm.zip,and can add this customized tab XML to the existing one with operating on XML file directly,however this is not what I want.

    Since this word template is used for end user who don't have any knowledge about Word dev,I perfer to import the Ribbon through a simple way like importing  UI file or register some dll file or add office add-in  etc.

    I look into the document on programming Application-level add-ins and programming Document-level customizations,but there are too much information and I am not familar with Visual Studio.I have a basic knowledge that I need to create a Word 2013 template project or a Word 2013 add-in project in Visual Studio,but how can I get this project to work on end user's application or document?

    Regards,

    Sarah


    • Edited by SarahSh Wednesday, September 25, 2013 6:45 AM add info
    Monday, September 23, 2013 2:45 AM
  • I have created a custom ribbon with one tab and serveral groups/commands(macros with VBA code) in a Word template,now I have exported all customziations and save it as an exportedUI file.After that I need import it to end users who will use this template and ribbon.But If the user inported it to the computer with "inport the customization file" in Word,all the existing custom setting were overwrited by my customized ribbon and qucik access toolbar.

    Question:

    Is there any way to inport the custom ribbon without overwriting the existing setting on another's computer?I look into the document on programming Application-level add-ins and programming Document-level customizations, and some other links about creating add-in project in Microsoft Visual Studio below

    http://technet.microsoft.com/en-us/library/cc178959(v=office.12).aspx#section3

    http://msdn.microsoft.com/en-us/library/vstudio/aa942955.aspx

    However I have never used Visul Studio before(only know a little about VBA) and there is too much information to get what  I really want . Can someone put me on the right track?

    Thanks in advance.

    Ps,I also submited a thread in word dev forum but didn't get the answer.

    Regards,

    Sarah



    Friday, September 27, 2013 3:09 AM
  • Any ones?

    Friday, September 27, 2013 6:39 AM
  • Hi Sarah

    The options availabe in Word's user interface for modifying the QAT and the Ribbon (not available in 2007) change the Ribbon for the entire interface and do replace what was originally there. These are meant for the user, not for individual documents.

    If you have a template and you want to share its customizations with other users, the better approach would probably be to save the template in the users' Startup folders. Where this is depends on 1) the version of Word and 2) whether a company has modified that location.

    Any template saved in this folder will automatically be loaded by Word as a "template add-in". All macros and Ribbon customizations, as well as building blocks and keyboard shortcuts, will be available at all times to the user. Yet what it provides will not interfere with the user's own customizations.


    Cindy Meister, VSTO/Word MVP, my blog

    Monday, September 30, 2013 6:18 PM
    Moderator