bumble_bee_tuna
bumble_bee_tuna

Reputation: 3563

Change Document template path in multiple Word Templates

I have about 500 word documents that I need to change the server name in the Document template path. I am not an expert with VBA but I have tried several solutions that have not worked for me. Is there a way to do this (perhaps with C#, with a foreach loop on the directory?) that I can do a very simple find and replace on this field ?

i.e.

\\ASDCFS\NtierFiles\...

becomes

\\NewServer\NtierFiles\...

enter image description here

Upvotes: 0

Views: 932

Answers (2)

Christoph
Christoph

Reputation: 11

You can use WTC to correct the template path in a bulk of documents. You find the source code and binary on Github: https://github.com/NeosIT/wtc

Upvotes: 1

Cindy Meister
Cindy Meister

Reputation: 25663

You can't write to the field in the dialog box directly. In the object model the equivalent is Document.AttachedTemplate and yes, you can work with that. Using in the object model (whether using VBA or C#) you'd loop the documents in a folder, open each in Word, assign the correct path, save and close.

More efficient and less prone to "hiccups" if the original template path is already invalid, would be to edit the documents' Word Open XML directly, without using the Word application. The Open XML SDK would be a good tool for this. It provides the AttachedTemplate class (https://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.attachedtemplate(v=office.14).aspx).

Upvotes: 1

Related Questions