Forum Discussion
andgoo_
Jun 18, 2024Copper Contributor
Update Word template programmatically
It is possible to manually apply a new Word template via the following steps:
- Open the Word document you would like to apply the template to, then click File > Options to
open the Word Options dialog box. - In the Word Options dialog box, click Add-ins in the left bar, select Templates from the
Manage drop down list, and click Go. - A new dialog box should appear for Templates and Add-ins. Check the “Automatically update
document” styles option and click the Attach button. - 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. - 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?
3 Replies
Sort By
- Charles_KenyonBronze Contributor
First, read:
- What is the relationship between a Microsoft Word document and its template?
- What happens when I attach a new template to my document? or How do I copy content and settings from a template to a document? by Shauna Kelly MVP
What is it you are trying to accomplish by attaching a different template?
- andgoo_Copper ContributorThanks 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_KenyonBronze Contributor
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.
- You can, instead, apply a [Quick] Style Set. [Quick] Style Sets and Word Themes in Microsoft Word
- 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.
- 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.