View Single Post
  #10   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default Automatic date change

The following macro will change all the date fields in documents in a
selected folder for createdate fields.

Sub BatchFixDates()
Dim myFile As String
Dim PathToUse As String
Dim MyDoc As Document
Dim iFld As Integer

With Dialogs(wdDialogCopyFile)
If .Display 0 Then
PathToUse = .Directory
Else
MsgBox "Cancelled by User"
Exit Sub
End If
End With
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
myFile = Dir$(PathToUse & "*.do?")
While myFile ""
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
MyDoc.Close SaveChanges:=wdSaveChanges
myFile = Dir$()
Wend
End Sub

or for the current document only

Sub FixDates()
ActiveDocument.ActiveWindow.View.ShowFieldCodes = True
Dim oRng As Range
Dim iFld As Integer
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
ActiveDocument.ActiveWindow.View.ShowFieldCodes = False
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


Jeff Lowenstein wrote:
John,

Can you provide some clear directions on how to do this? I am
working currently with both woord 2003 & 2007. I have documents that
were generated using the built-in contemporary memo. It is using the
DATE field. How do I automatically detect and fix this error for
documents that I didn't create?

Thanks,

Jeff

"John McGhie [MVP - Word and Word Macinto" wrote:

Hi Seattle:

I guess you're not feeling so well after SuperBowl, huh?

When you feel better, you need to replace the DATE field in all of
those documents with a CREATEDATE or PRINTDATE field.

There's no way you can prevent a DATE field updating to the current
date on document open.

But if you change the field to Create Date or Print Date, it will
change back to the correct date of those operations.

I would make an AutoText to replace the Date Field with a CreateDate
field (which will give the date the document was created).

Cheers


On 4/2/06 2:03 AM, in article
, "Seattle777"
wrote:

When I follow these instructions, it does correct the problem for
the document I have already opened. How can I set it so it does not
automatically update the date on every other document that I open
up later, without having to go through this process on each
document?

"Charles Kenyon" wrote:

AutoUpdate only changes a field as you insert it. Once it is
inserted it is what it is unless _you_ change it.

You are using a DATE or TIME field rather than a CREATEDATE field.
This field should be put in the original template if possible
(instead of inserting using the keyboard shortcut or header/footer
toolbar button).

In the document in question, press Alt-F9 to display field codes.
Then change the field to a CREATEDATE field, press F9 and then
Alt-F9.

See
http://addbalance.com/word/datefields1.htm for information on
the different kinds of datefields and how to format them.

--

Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version
of Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
"bogiebob" wrote in message
...
When I open saved word documents, such as letters or faxes, they
open with the current date. Auto update is off in date & time
format. HELP! How can
I keep the date the document was written as the date on the
document.




--

Please reply to the newsgroup to maintain the thread. Please do not
email me unless I ask you to.

John McGhie
Microsoft MVP, Word and Word for Macintosh. Consultant Technical
Writer Sydney, Australia +61 (0) 4 1209 1410