none
Microsoft.Office.Interop.Word.Templates collection RRS feed

  • Question

  • Hi Everyone!

    Happy Friday!

    I trying to figure out how to access a custom building blocks template using C# and VS 2010 (application level add-in for Word.)  I have written some code to access the Normal template, but I want to move the building blocks out of Normal.dotx to Abbreviations.dotx.  So I need to learn how to use the Microsoft.Office.Interop.Word.Templates collection.

     

    Does anyone have any examples that use this collection?

     

    Thank you for your help!

     

    The code

    • Moved by Rudedog2 Friday, January 20, 2012 11:02 PM : move to more apprrpriate forum : (From:Visual C# General)
    Friday, January 20, 2012 7:31 PM

Answers

  • Hi Susan

    Something like this, to pick up a particular template that's already loaded in Word as an "add-in template". Normal.dotm will always be loaded. Word will also load anything it finds in the designated Startup folder.

    Word.Templates tpls = WordApplication.Templates;
    Word.Template tpl = tpls(filePathForTemplate);

    If you want to load a particular template that's not in the Startup folder, then

    object oTrue = true;
    Application.AddIns.Add(filePathForTemplate, ref oTrue);
    //now pick up the template as above as it's not possible to cast an Addin object to a Template object

    Note: I'm typing this from memory, so there may be some minor syntax errors.


    Cindy Meister, VSTO/Word MVP
    Sunday, January 22, 2012 7:31 AM
    Moderator

All replies

  • Hi Susan

    Something like this, to pick up a particular template that's already loaded in Word as an "add-in template". Normal.dotm will always be loaded. Word will also load anything it finds in the designated Startup folder.

    Word.Templates tpls = WordApplication.Templates;
    Word.Template tpl = tpls(filePathForTemplate);

    If you want to load a particular template that's not in the Startup folder, then

    object oTrue = true;
    Application.AddIns.Add(filePathForTemplate, ref oTrue);
    //now pick up the template as above as it's not possible to cast an Addin object to a Template object

    Note: I'm typing this from memory, so there may be some minor syntax errors.


    Cindy Meister, VSTO/Word MVP
    Sunday, January 22, 2012 7:31 AM
    Moderator
  • Thanks Cindy,

    That's what I needed to get started!

    Monday, January 23, 2012 5:13 PM