Stop automatic date update

Home Up Search This Site What's New? Audio On CDR Favourites Downloadable files Photo Gallery 2002 Photo Gallery 2003 Photo Gallery 2004/5 Photo Gallery 2006/7 Photo Gallery 2008 UK Photo Gallery Ireland Photo Gallery Cats Photo Gallery 

 

 

Google
 

 

 

There is no charge for using any of the material (for personal use) on this web site, but if you wish to make a contribution to the ever growing running costs, any donation would be much appreciated. Click the adjacent button to access PayPal

Stop automatic date update!

 

Users frequently complain that dates they have inserted into Word documents update automatically when the document is opened. The reason is that they have inserted a DATE field which shows the system date. What is needed is change those date fields for CREATEDATE fields, which when updated will display the dates the documents were created -

ALT+F9 change {DATE \@ "d MMM yyyy"}or {TIME \@ "d MMM yyyy"} to {CREATEDATE \@ "d MMM yyyy"} then F9 and ALT+F9 - and change the date in the template so that future documents based on it show the correct dates. The first of the macro listings below will change any DATE field in an open document or template to a CREATEDATE field. The switches \@ "d MMM yyyy" may be different at your location.

However you may now have a folder full of documents containing DATE fields and may wish to process them all in a batch. The second macro uses the code from the first macro and applies it to all the files in a chosen folder.

Note:

Create a new folder and copy the files that you wish to change into it, before running the macro. It is always advisable to work with copies when batch processing, as you could destroy a lot of work if there is an unexpected problem!

 

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

Note: For more information about installing macros use this link