Automated replacement of Word template paths

Hi All

We have just changed from an old Novell Server to a Windows Server. As a direct consequence, all of our thousands of Word documents have the path to the templates which resided on the Novell Server, accordingly they each take minutes to open.

I would be very grateful if someone could tell me if there is an automated routine that would replace the start of the string that comprises the embedded template in each Word document.

Hi Paul, thank you for your response. I saw this support article and option 3 looks like the closest one to what I want to achieve, but it would need to be modified to loop through all of the Word files in all of the sub-directories of the main folder that it is started in, specifically replacing the path \\TSB\Vol1 with H: in all of the attached templates, if found (there are Word files that have the Normal.dot template attached).

I would be happy to pay for such a modification, given that I don't know how to do it myself.

Note: Test it on a folder containing just a couple of files first - you may yet need to change the path variables. Note also that the code doesn't process protected files and that mailmerge main documents and other documents containing macros may cause problems, due to their own prompts.

I created a Test folder on our new server with a single Word file in it, with the old path to the attached Template, as you suggested.

I then copied and pasted your code into a new macro and ran it, selecting the required Test folder. The code ran, displaying 'Contacting \\TSB\Vol1\Doc\Gen\Word2002 press Esc to cancel' on the status bar, then displayed 'Contacting \\TSB press Esc to cancel' and then eventually it finished, displaying '0 of 1 files updated'.

I then created a sub-directory under Test and put the Word file into that, thinking that the code needed it, but it still failed.

Although the only difference in the Template path is that \\TSB\Vol1 becomes H:, I then tried to modify the OldServer and NewServer values in the code, eventually entering the whole path \\TSB\Vol1\Doc\Gen\Word2002 where the Templates are and repeating it with H:\Doc\Gen\Word2002 but it still failed.

I would be grateful if you could look at the code and hopefully find what needs to be changed.

In the code, you'll see the line 'OldServer = "<\\TSB\Vol1>": NewServer = "H:"'. It's critical that both server names be correct; otherwise, either the old one won't be replaced or the new one will be invalid too.

Previously, you mentioned that the old server's name was '\\TSB\Vol1', which I've encoded as 'OldServer = "<\\TSB\Vol1>"'. I based that on the MS example, but you may need to delete the chevrons.

Also, it seems that what you provided before wasn't the full template path. If it's going to work, the code needs the full paths for both the old and new templates. Conversely, if it's only part of the path that has changed and there are various branches above that to various templates, all of which you're trying to update references to simultaneously, the code would need further modification. Even so, you're going to encounter a message like 'Contacting \\TSB\Vol1 press Esc to cancel', simply because the old server can't be found (unless you temporarily re-connect it).

As for the new server's path to the templates, I suggest trying to update one document's template path manually, then checking how that is depicted in Word.

Clearly I have not understood. I thought that you could just write code that would replace one string with another, hence my request of replacing \\TSB\Vol1 with H:

We have changed from a Novell Server to a Windows Server. The Novell Server was called \\TSB and it had Volumes, as Novell does.

The Templates were located on Vol1 in the directory Doc\Gen\Word2002, the full UNC path being \\TSB\Vol1\Doc\Gen\Word2002, which I have noticed, is the path of the attached template currently in each Word file. This is what we need to change.

We have kept the file structures that same, but as Windows does not have Volumes, Vol1 has become the H: drive.

Sorry - a bit of mis-direction on my part. The adapted code does replace just part of the path. It seems that correctly identifying the path to be replaced is the issue. To that end, you can confirm the attached template path for a given document using:

Code:

Sub Test()
MsgBox ActiveDocument.AttachedTemplate.Path
End Sub

Based on your latest advice, it appears the new server should be specified as 'NewServer = "\\TSLSERVER\Files"'

An alternative approach is to change the 'UpdateTemplateRefs' macro to:

I ran your Test macro on the old test Word document and it returned the Template Path as \\TSB\Vol1\Doc\Gen\Word2002. I then confirmed this using File | Options | AddIns | Manage Templates and it was the same.

I repeated this on a new Word document and the path was H:\Doc\Gen\Word2002.

I then performed a series of tests, running the original UpdateServer code:

Step through the macro by pressing F8 for each line. Hover the mouse over pieces of the code to see what the values are. I would be particularly interested in the following line both before and after it executes

.AttachedTemplate = NewPath & "\" & .AttachedTemplate.NameNote that line that opens the word document is likely to take minutes to work for each document. You could drastically speed this up if you renamed one of your machines on the network so that the old address was valid for the duration of the macro running.

I assume you didn't rename the old templates to the newer formats (which have a different suffix) because that would certainly cause the macro to fail.