none
Attaching a template to an existing document RRS feed

  • Question

  • I am converting an ancient Word automation to Word 2010.  The goal is to override some of the commands on the "File" tab on the ribbon. I created a template project and compiled it into a dotm. When I double-click on the dotm, the ribbon interface is correct. 

    However, I need to have this new ribbon up and running when I open existing files (old .doc files) in C#, and it's not working. 

    Here is the code I'm using:

    string fpath = "\\resources\\Template1.dotm";
    string apath = Application.StartupPath;
    string sPath = apath + fpath;
                                            
    oDocument = oWord.Documents.Open(FileName: oFileName, ReadOnly: oReadOnly); 

    object intValue = 1;
    Word.Documents docs = oWord.Documents;
    oDocument = docs.get_Item(ref intValue);
                            
    object path = (object)sPath;
    if (File.Exists(sPath))
    {
        oDocument.Convert();
        oDocument.set_AttachedTemplate(ref (path));
    }                       

    The document opens, but it has the standard ribbon. There are no errors, but the new template is not attached.  What am I missing?

    Thank,

    Paula Moore

    Wednesday, May 30, 2012 5:37 PM

Answers

  • I found a link at MSDN that seems to do the trick:   http://msdn.microsoft.com/en-us/library/zcfbd2sk#HowCustomizationsWork  

    I convert the document from 2003 to 2010 and then add the ribbon to the document. 

    Thanks,

    Paula

    Saturday, June 2, 2012 1:26 AM

All replies

  • Hi Paula,

    Thanks for posting in the MSDN Forum.

    In my opinion, the ribbon is leaving on Office suites (for example Word, Excel, PowerPoint, Outlook etc.). It will not change with the document. As the dotm file which your mentioned is a document-level application. It attached some VSTO assemblies. If you want the .doc file have a customized ribbon you are able to follow the setps which I will show you to approach it.

    1. create a Word document application in Visual Studio .
    2. Use your doc file in Create Wizard under Copy a exist document field.
    3. Customized ribbon in project.
    4. Build the project.
    5. You will get some files in bin\Debug folder which include a new doc file.

    the new doc file is the one which you want. Please notice the the file in bin\Debug is prerequisites of the doc file which has customized ribbon.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, May 31, 2012 3:02 AM
    Moderator
  • I found a link at MSDN that seems to do the trick:   http://msdn.microsoft.com/en-us/library/zcfbd2sk#HowCustomizationsWork  

    I convert the document from 2003 to 2010 and then add the ribbon to the document. 

    Thanks,

    Paula

    Saturday, June 2, 2012 1:26 AM
  • Hi shesamodiste,

    I'm glad to hear you have solved it via yourself. Thanks for sharing your experience here, it's very beneficial for other community members who have similar questions to see how you solved it.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, June 5, 2012 6:11 AM
    Moderator