Forum Discussion

andgoo_'s avatar
andgoo_
Copper Contributor
Jun 18, 2024

Update Word template programmatically

It is possible to manually apply a new Word template via the following steps:

 

  1. Open the Word document you would like to apply the template to, then click File > Options to
    open the Word Options dialog box.
  2. In the Word Options dialog box, click Add-ins in the left bar, select Templates from the
    Manage drop down list, and click Go.
  3. A new dialog box should appear for Templates and Add-ins. Check the “Automatically update
    document” styles option and click the Attach button.
  4. A new dialog box should appear for Attach Template. In this new box, open the folder
    containing the new template to be applied, select the new template, and click the Open
    button.
  5. Click the OK button when it returns to the Templates and Add-ins dialog box. The specified Word template should now be applied to the existing Word document.

 

Edit:
To clarify the scenario - We have a large number of existing documents using an old template which specifies header, footer & styling etc.
A new template has been created with updated styling and this needs to be applied to hundreds of existing documents. This is not viable to be done manually. 

Therefore the question - Is it possible to perform updating of a Word template programmatically?

6 Replies

  • To reformat an existing document using a template, what you can do is create a new document based on your (new or modified) template and then import existing content, for example via the Insert File dialog box. This can be done via VBA, although I am not the right person to suggest the details for implementing it.

     

    P.S. I just realized that this is an old thread, so any updates may not reach the original poster. 

  • I concur with Charles Kenyon. Applying a theme will quickly change styles. BUT I realize that's not what you want to do. Templates will not change the content of an existing document (nor do you really want them to).

    Frankly, after 35 yrs using Word, I'd freak out if it were possible to programmatically change the content of hundreds of documents. Something, something unintended consequences?

    While the thought of revising styles, headers (logo too, maybe?) on hundreds of documents seems agonizing, this might be an opportunity to review the content as well. We all suffer from digital detritus.

    • Make copies! Keep the historical docs as they were 20 yrs ago and archive them (check your company's records and retention policy). 
    • Farm out review to coworkers or review the most frequently used first.
    • Check to make sure that with your new styles, page breaks occur where you want them.
  • joelbbarker's avatar
    joelbbarker
    Copper Contributor

    I share this struggle. I recommend looking into a path OUT of Microsoft to a more abstracted content type like ASCIIDoc or extended markdown. It is hard. I suspect that the process needs to have some human intervention, not a massive batch processing. I have not achieved it yet, sadly.

    My post is not a solution, but sympathy.

    • andgoo_'s avatar
      andgoo_
      Copper Contributor
      Thanks for replying Charles.
      I'm already aware of the relationship between a Word document and its template.
      Obviously what I'm doing by attaching a different template us to apply a new template to a document which is using an old template with out-of-date formatting.

      What I'm trying to accomplish is performing this task via code/script instead of manual steps.

      • Charles_Kenyon's avatar
        Charles_Kenyon
        Bronze Contributor

        andgoo_ 

        The only formatting that can change by applying a new template to an existing document is Styles. Page layout and other formatting is not changed.

        1. You can, instead, apply a [Quick] Style Set. [Quick] Style Sets and Word Themes in Microsoft Word 
        2. You can, instead, use the Organizer to copy styles. This can be done programmatically. See my webpage: A Global StyleSheet in Microsoft Word? and the demonstration sample Outline Heading Styles Global Stylesheet Add-In.
        3. Or, you can programmatically attach the template updating styles. I think the first two options are superior unless that template has something else you want like building blocks, keyboard shortcuts, or macros. In that case, though, why not simply load the template as an Add-In? That gives access to all of those without a change to the document's attached template.

        If you really want option 3, I can write a macro for you. It may take me a couple of days because I have a day job.

Resources