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 Photo Gallery 2009/10 UK Photo Gallery Ireland Photo Gallery Cats Photo Gallery 

 

 

Google
 

 

Many people access the material from this web site daily. Most just leech what they want and run. That's OK, provided they are not selling on the material as their own; however if your productivity gains from the material you have used, a donation from the money you have saved, however small, would help to ensure the continued availability of this resource.

Click the appropriate button above 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 } to { CREATEDATE \@ "d MMMM 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 MMMM 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.

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 sSwitch As String
Dim
iFld As Integer

'Set the required date switch - note the quotes
sSwitch = " \@ ""d MMMM yyyy"""

'Check each field in the document
For
iFld = ActiveDocument.Fields.Count To 1 Step -1
     With
ActiveDocument.Fields(iFld)
          Select Case
.Type

          'The field is a Date field
          Case Is =
wdFieldDate

               'Change it to a Createdate field
              
.Code.Text = Replace(UCase(.Code.Text), _
                   "DATE", "CREATEDATE")

               'If there is no date switch - add one
               If
InStr(1, .Code, "\@") = 0 Then
                   
.Code.Text = .Code.Text & sSwitch
               End If
              
.Update

          Case Else
          End Select
     End With
Next
iFld
End Sub
 

Sub BatchFixDates()
Dim
strFile As String
Dim
strPath As String
Dim
sSwitch As String
Dim
strDoc As Document
Dim
iFld As Integer
Dim
fDialog As FileDialog

'Set the required date switch - note the quotes
sSwitch = " \@ ""d MMMM yyyy"""
Set
fDialog = Application.FileDialog(msoFileDialogFolderPicker)

'Get the folder containing the documents
With
fDialog
    
.title = "Select folder containing the documents to be processed and click OK"
     .AllowMultiSelect = False
     .InitialView = msoFileDialogViewList

     If
.Show <> -1 Then
         
MsgBox "Cancelled By User", , "List Folder Contents"
          Exit Sub
     End If
    
strPath = fDialog.SelectedItems.Item(1)
     If
Right(strPath, 1) <> "\" Then strPath = strPath + "\"
End With

'If there are any open documents, close them (prompting to save changes)
If
Documents.Count > 0 Then
    
Documents.Close SaveChanges:=wdPromptToSaveChanges
End If
strFile = Dir$(strPath & "*.doc")

'Open each document in the folder
While
strFile <> ""
     Set
strDoc = Documents.Open(strPath & strFile)

     'Check each field in the document
     For
iFld = ActiveDocument.Fields.Count To 1 Step -1
          With
ActiveDocument.Fields(iFld)
              
'The field is a Date field

               Select Case .Type
               Case Is
= wdFieldDate

                    'Change it to a Createdate field
                   
.Code.Text = Replace(UCase(.Code.Text), _
                        "DATE", "CREATEDATE")

                    'If there is no date switch - add one
                    If
InStr(1, .Code, "\@") = 0 Then
                        
.Code.Text = .Code.Text & sSwitch
                    End If

                    .Update
               Case Else
               End Select
          End With
     Next
iFld

     'Save the changes
    
strDoc.Close SaveChanges:=wdSaveChanges
     strFile = Dir$()

Wend
End Sub
 

Note: For more information about installing macros use this link