none
Load a new template file RRS feed

  • Question

  • Hello,

    I created a word-Add in. A Word template and VBA Code with forms.

    Now I want to load out of the add in an other template instead of the "add in template".

    Is this possible? And how?

    Regards Andreas


    http://www.AccessBlog.de

    Tuesday, June 26, 2012 9:41 PM

Answers

  • If your add-in is a global, then Stefan is correct, the code remains isolated from any DOCUMENT template.  You can change the document template of any given document with the AttachedTemplate property.  This can certainly be done via code from an add-in.

    That being said, global add-ins do NOT have to be in Startup.  In fact I recommend that they not be, especially in a corporate or network environment.  Globals can be loaded and unloaded dynamically.  They can be in ANY folder, including a centrally managed network folder.  Add-ins loaded via Startup remain in memory; they are static that way.  They could very well have lots of code that is not relevant to a particular set of tasks.  Better to "chunk" out code into various globals (String functions, graphics...whatever) designed for understandable purposes - rather than some generic massive add-in.

    In our environment, we have a wee Startup global (tiny) that has only ONE piece of code - code that loads various other globals from a network folder dynamically, on demand.

    You want the Financials global?  It can be loaded (and unloaded) as required.

    You want the Personnel global?  It can be loaded (and unloaded) as required.

    You want the Graphics global?  It can be loaded (and unloaded) as required.

    Etc. etc.

    I too am a little uncertain as to what exactly you are asking for.


    Word MVP

    Thursday, June 28, 2012 4:52 AM
  • Or with a custom interface (pre-2007 as menus, or icons) pointing to code to load specific add-ins.  I usually use them as toggles; click Finance - if not loaded, load it; if loaded, unload it.  Having users navigate Templates and Add-ins can be confusing, plus having behind the scene code allows multiple (or complex) paths to an Add-in folder that users can not mess up.

    OK, I will explain what I'm doing: I have written an Add In to create invoices. The Word-Sheet has the Textmarkers and the Design, the VBA "behind" has the logic to fill in. Now I want that people can load own defined Word-sheets with their own Design with the same Textmarkers "into/onto" the Add In like you change the theme/template of a webside. When a user opens the Add In he should be able to select the Template on wich the invoice are printed.

    Andreas, there may be some confusion about add-ins versus templates.  Templates, while they can also have code, are the design of documents.  Add-ins are basically code containers.

    So IF various templates (designed documents) are to be used, AND these various templates have the same "textmarkers" (I assume you mean bookmarks) by name, then the code in the add-in can function in all the various templates.  So have the user pick the template, and execute the code from the add-in.  There is only going to be a problem if the logic in the add-in points to conflicting elements (bookmarks) in each different template.

    You do not load a template into an add-in.  Again, essentially add-ins are code containers, NOT documents.  Comparing it to a web site is not a good way of looking at it.

    In other words, IF the add-in is in memory (via Startup, or dynamically), have the user make a document with whatever template they want, and run the code.

    Although, the use of various templates designs to do the same task seems a little odd.

    a user opens the Add In

    Users (or anyone else besides the developer) never "open" an add-in.  Add-ins are not opened.  They are either loaded into memory, or they are not loaded into memory.  That is it.

    But again, for your code to work in different templates, the various templates used MUST use identical elements.


    Word MVP


    Friday, June 29, 2012 5:48 AM

All replies

  • You can change the attached template in the Templates and Add-Ins dialog box, if that's what you're asking. (To open the dialog box, click the Document Template button on the Developer tab.)

    Stefan Blom, Microsoft Word MVP
    Wednesday, June 27, 2012 2:38 PM
  • Hello,

    no this isnt what I'm asking.

    I want wo "overwrite" by vba the default template with an other but using stil the VBA-Code from the Addin.

    (Addin <-> Template with VBA Code?)

    Regards Andreas


    http://www.AccessBlog.de

    Wednesday, June 27, 2012 3:42 PM
  • Hello,

    no this isnt what I'm asking.

    I want wo "overwrite" by vba the default template with an other but using stil the VBA-Code from the Addin.

    (Addin <-> Template with VBA Code?)

    Regards Andreas


    http://www.AccessBlog.de

                
           
             
    "Overwrite" in what sense? (Maybe I'm missing something obvious here...)
            
    You can do anything to the documents open in a Word session; it won't affect the add-ins. (I'm assuming here that we are talking about "global template add-ins" in the Startup folder; these are loaded into memory when Word starts, giving all documents access to the macros, Building Blocks, and keyboard shortcuts stored in the add-ins).

    Stefan Blom, Microsoft Word MVP

    Wednesday, June 27, 2012 6:23 PM
  • If your add-in is a global, then Stefan is correct, the code remains isolated from any DOCUMENT template.  You can change the document template of any given document with the AttachedTemplate property.  This can certainly be done via code from an add-in.

    That being said, global add-ins do NOT have to be in Startup.  In fact I recommend that they not be, especially in a corporate or network environment.  Globals can be loaded and unloaded dynamically.  They can be in ANY folder, including a centrally managed network folder.  Add-ins loaded via Startup remain in memory; they are static that way.  They could very well have lots of code that is not relevant to a particular set of tasks.  Better to "chunk" out code into various globals (String functions, graphics...whatever) designed for understandable purposes - rather than some generic massive add-in.

    In our environment, we have a wee Startup global (tiny) that has only ONE piece of code - code that loads various other globals from a network folder dynamically, on demand.

    You want the Financials global?  It can be loaded (and unloaded) as required.

    You want the Personnel global?  It can be loaded (and unloaded) as required.

    You want the Graphics global?  It can be loaded (and unloaded) as required.

    Etc. etc.

    I too am a little uncertain as to what exactly you are asking for.


    Word MVP

    Thursday, June 28, 2012 4:52 AM
  • Hi, thanks for answer.

    OK, I will explain what I'm doing: I have written an Add In to create invoices. The Word-Sheet has the Textmarkers and the Design, the VBA "behind" has the logic to fill in. Now I want that people can load own defined Word-sheets with their own Design with the same Textmarkers "into/onto" the Add In like you change the theme/template of a webside. When a user opens the Add In he should be able to select the Template on wich the invoice are printed.

    Regards Andreas


    http://www.AccessBlog.de

    Thursday, June 28, 2012 6:39 AM
  • That being said, global add-ins do NOT have to be in Startup. In fact I recommend that they not be, especially in a corporate or network environment. Globals can be loaded and unloaded dynamically.
     
     
    Good point. Thanks for the reminder. (Obviously, in the user interface, you can load and unload such templates via the Templates and Add-Ins dialog box.)

    Stefan Blom, Microsoft Word MVP
    Thursday, June 28, 2012 6:01 PM
  • Or with a custom interface (pre-2007 as menus, or icons) pointing to code to load specific add-ins.  I usually use them as toggles; click Finance - if not loaded, load it; if loaded, unload it.  Having users navigate Templates and Add-ins can be confusing, plus having behind the scene code allows multiple (or complex) paths to an Add-in folder that users can not mess up.

    OK, I will explain what I'm doing: I have written an Add In to create invoices. The Word-Sheet has the Textmarkers and the Design, the VBA "behind" has the logic to fill in. Now I want that people can load own defined Word-sheets with their own Design with the same Textmarkers "into/onto" the Add In like you change the theme/template of a webside. When a user opens the Add In he should be able to select the Template on wich the invoice are printed.

    Andreas, there may be some confusion about add-ins versus templates.  Templates, while they can also have code, are the design of documents.  Add-ins are basically code containers.

    So IF various templates (designed documents) are to be used, AND these various templates have the same "textmarkers" (I assume you mean bookmarks) by name, then the code in the add-in can function in all the various templates.  So have the user pick the template, and execute the code from the add-in.  There is only going to be a problem if the logic in the add-in points to conflicting elements (bookmarks) in each different template.

    You do not load a template into an add-in.  Again, essentially add-ins are code containers, NOT documents.  Comparing it to a web site is not a good way of looking at it.

    In other words, IF the add-in is in memory (via Startup, or dynamically), have the user make a document with whatever template they want, and run the code.

    Although, the use of various templates designs to do the same task seems a little odd.

    a user opens the Add In

    Users (or anyone else besides the developer) never "open" an add-in.  Add-ins are not opened.  They are either loaded into memory, or they are not loaded into memory.  That is it.

    But again, for your code to work in different templates, the various templates used MUST use identical elements.


    Word MVP


    Friday, June 29, 2012 5:48 AM