R
Richard Conway
Hi there, I need some help writing a macro that will change the Document
Template. The problem is that we have around 60,000 word documents that all
have document templates to which the path points to a server that no longer
exists. As a consequence every time one of the files is opened, Word hangs
for a while until it figures out it can't find the template, and then opens
the file. This is very annoying as you can imagine! I have written the
following macro:
Sub ChangeTemplateToNormal()
Dim i As Long
Dim strSaveFile As String
With Application.FileSearch
.FileName = "*.doc"
.LookIn = "<path to folder>"
.SearchSubFolders = False
.Execute
If .FoundFiles.Count > 0 Then
For i = 1 To .FoundFiles.Count
Documents.Open FileName:=.FoundFiles(i)
With ActiveDocument
.UpdateStylesOnOpen = False
.AttachedTemplate = "normal"
.Save
.Close
End With
Next i
End If
End With
End Sub
Which works fine up until a point but because of the shear number of files
involved it tends to crash frequently. Does anybody have any recomendations
of how I could add some error trapping into the script so it will carry when
it encounters an error?
Thanks in advance,
Ric.
Template. The problem is that we have around 60,000 word documents that all
have document templates to which the path points to a server that no longer
exists. As a consequence every time one of the files is opened, Word hangs
for a while until it figures out it can't find the template, and then opens
the file. This is very annoying as you can imagine! I have written the
following macro:
Sub ChangeTemplateToNormal()
Dim i As Long
Dim strSaveFile As String
With Application.FileSearch
.FileName = "*.doc"
.LookIn = "<path to folder>"
.SearchSubFolders = False
.Execute
If .FoundFiles.Count > 0 Then
For i = 1 To .FoundFiles.Count
Documents.Open FileName:=.FoundFiles(i)
With ActiveDocument
.UpdateStylesOnOpen = False
.AttachedTemplate = "normal"
.Save
.Close
End With
Next i
End If
End With
End Sub
Which works fine up until a point but because of the shear number of files
involved it tends to crash frequently. Does anybody have any recomendations
of how I could add some error trapping into the script so it will carry when
it encounters an error?
Thanks in advance,
Ric.