Sub FixDates()
Dim iFld As Integer
'Display the field codes so
that they may be edited
ActiveDocument.ActiveWindow.View.ShowFieldCodes = True
'Checkout all the
fields
For iFld = ActiveDocument.Fields.Count
To 1 Step -1
With ActiveDocument.Fields(iFld)
'If the field is a
DATE field
If .Type = wdFieldDate
Then
'Change it to a CREATEDATE field
.Code.Text = replace(.Code.Text, "DATE", "CREATEDATE")
.Update 'Update the field
End If
End With
Next iFld 'Check for more DATE
fields
'And show the result
ActiveDocument.ActiveWindow.View.ShowFieldCodes = False
End Sub
Sub BatchFixDates()
Dim myFile As String
Dim PathToUse As String
Dim MyDoc As Document
Dim iFld As Integer
With Dialogs(wdDialogCopyFile)
'Select the folder
containing the documents to be processed
If .Display <> 0
Then
PathToUse = .Directory
Else
MsgBox "Cancelled by User"
Exit Sub
End If
End With
'If there are any
documents open, close them, giving the option to save
If Documents.Count > 0
Then
Documents.Close SaveChanges:=wdPromptToSaveChanges
End If
If Left(PathToUse, 1) = Chr(34) Then
PathToUse = Mid(PathToUse, 2, Len(PathToUse) - 2)
End If
'Select the
document/templates in the chosen folder
myFile = Dir$(PathToUse & "*.do?")
While myFile <> ""
'Process all that
match the name in turn
Set MyDoc = Documents.Open(PathToUse & myFile)
ActiveWindow.View.ShowFieldCodes =
True
For
iFld = ActiveDocument.Fields.Count To 1
Step -1
With ActiveDocument.Fields(iFld)
If .Type = wdFieldDate
Then
.Code.Text = replace(.Code.Text, "DATE", "CREATEDATE")
.Update
End If
End With
Next iFld
ActiveWindow.View.ShowFieldCodes =
False
'Save and close
the document with the changes
MyDoc.Close SaveChanges:=wdSaveChanges
myFile = Dir$()
Wend
End Sub