I have thousands of word documents that have references to their original templates that were on one server but have been moved to a new server. This reference to a non-existent location makes the files take several minutes to load. I need to go through all the .doc files and replace the references to the old server with the new one. Ive found lots of examples of how to do something like this but cant get any of them to actually work. Ive got this far with a script I found that will actually run. It will open all the word docs. But when i check the .doc files that it has processed, the old server reference has not been changed. Can anybody point me toward what might be going wrong or point me in another direction if this wont work?
Sub rename_temp_dir()
Dim strFilePath As String
Dim strPath As String
Dim intCounter As Integer
Dim strFileName As String
Dim OldServer As String
Dim NewServer As String
Dim objDoc As Document
Dim objTemplate As Template
Dim dlgTemplate As Dialog
OldServer = "\\oldserver\share1\wordtemps"
NewServer = "\\newserver\share1\wordtemps"
strFilePath = InputBox("What is the folder location that contains the documents?")
If Right(strFilePath, 1) <> "\" Then strFilePath = strFilePath & "\"
strFileName = Dir(strFilePath & "*.doc")
Do While strFileName <> ""
Set objDoc = Documents.Open(strFilePath & strFileName)
Set objTemplate = objDoc.AttachedTemplate
Set dlgTemplate = Dialogs(wdDialogToolsTemplates)
strPath = dlgTemplate.Template
If LCase(Left(strPath, 21)) = LCase(OldServer) Then
objDoc.AttachedTemplate = NewServer & Mid(strPath, 22)
End If
strFileName = Dir()
objDoc.Save
objDoc.Close
Loop
Set objDoc = Nothing
Set objTemplate = Nothing
Set dlgTemplate = Nothing
End Sub
Sub rename_temp_dir()
Dim strFilePath As String
Dim strPath As String
Dim intCounter As Integer
Dim strFileName As String
Dim OldServer As String
Dim NewServer As String
Dim objDoc As Document
Dim objTemplate As Template
Dim dlgTemplate As Dialog
OldServer = "\\oldserver\share1\wordtemps"
NewServer = "\\newserver\share1\wordtemps"
strFilePath = InputBox("What is the folder location that contains the documents?")
If Right(strFilePath, 1) <> "\" Then strFilePath = strFilePath & "\"
strFileName = Dir(strFilePath & "*.doc")
Do While strFileName <> ""
Set objDoc = Documents.Open(strFilePath & strFileName)
Set objTemplate = objDoc.AttachedTemplate
Set dlgTemplate = Dialogs(wdDialogToolsTemplates)
strPath = dlgTemplate.Template
If LCase(Left(strPath, 21)) = LCase(OldServer) Then
objDoc.AttachedTemplate = NewServer & Mid(strPath, 22)
End If
strFileName = Dir()
objDoc.Save
objDoc.Close
Loop
Set objDoc = Nothing
Set objTemplate = Nothing
Set dlgTemplate = Nothing
End Sub