View Single Post
  #6   Report Post  
Posted to microsoft.public.word.newusers
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default Template question

You can fix all your existing documents in a folder by running the following
macro, which will replace DATE field with CREATEDATE fields
Change the switch in the line sSwitch = " \@ ""d MMMM yyyy""" to your local
requirement. This switch is required as Createdate fields may not display
the same format as date fields. Any existing switches are retained.

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
sSwitch = " \@ ""d MMMM yyyy"""
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
With fDialog
.title = "Select folder 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 Documents.Count 0 Then
Documents.Close SaveChanges:=wdPromptToSaveChanges
End If
strFile = Dir$(strPath & "*.do?")
While strFile ""
Set strDoc = Documents.Open(strPath & strFile)
For iFld = ActiveDocument.Fields.Count To 1 Step -1
With ActiveDocument.Fields(iFld)
Select Case .Type
Case Is = wdFieldDate
.Code.Text = Replace(UCase(.Code.Text), _
"DATE", "CREATEDATE")
If InStr(1, .Code, "\@") = 0 Then
.Code.Text = .Code.Text & sSwitch
End If
.Update
Case Else
End Select
End With
Next iFld
strDoc.Close SaveChanges:=wdSaveChanges
strFile = Dir$()
Wend
End Sub

http://www.gmayor.com/installing_macro.htm

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org



Ross Moody wrote:
Thank you and the previous poster for the prompt reply. Ross

"Stefan Blom" wrote in message
...
Replace the inserted DATE field with a CREATEDATE field: Open each
of the documents. Press Alt+F9 to show field codes. Just type in
CREATEDATE instead of DATE. Press F9. Press Alt+F9 again to hide
field codes. Also, make sure to change the field in the template (for
future
documents).

--
Stefan Blom
Microsoft Word MVP



"Ross Moody" wrote in message
...
I have a large number of archived letters that I wrote with the aid
of a word template. Each time I open them for reference, word
automatically updates the archived letter to the current date. I
prefer to leave the original date unchanged. How can I do this but
not destroy the templates attributes for newly developed letters?
Thanks. Ross