Macro to change date field

H

hagen31

How do I edit this field in a header or footer

{ DATE \@ "M/d/yyyy" }

with a macro so it shows up as

Auto Date

Doing a find and replace doesn't remove the { } and still shows up as the
current date when you toggle.

Example will show up as { Auto Date } in code view and 8/16/2007 in regular
view.

Also, how would I edit it if the Date field was in the body of the text.
 
D

Doug Robbins - Word MVP

What is Auto Date meant to represent?

Maybe one of

SaveDate
PrintDate
CreateDate

is really what you are needing.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
H

hagen31

Nope that doesn't help.

Auto Date represents the text Auto Date. I don't actually want a date to
show up. I just want the text <Auto Date> to show up excatly like I just
typed it.

I have several docuements I need to do this on. So I don't want to have to
open the document up and delete the header footer and change it to the text
Auto Date everytime.
 
H

hagen31

I have figured part of it out.

Here is my code that I get from run the Record macro button

ActiveWindow.View.ShowFieldCodes = Not ActiveWindow.View.ShowFieldCodes
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^d DATE \@ ""M/d/yyyy"""
.Replacement.Text = "<Auto Date>"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

This works when recording the macro, but when I go to run it it doesn't find
it. I could have this search string in the header footer or body of the text
so I don't want to see the Active window to the footer becuase then it would
miss it in the header and body of the text.

Any idea why it works great when recording, but once I shut off the recorder
and try to run it it only shows me the field codes and doesn't change
anything.
 
H

hagen31

Yes that did help. I came across that article yesterday but was hung up on
it. Now I have it.
 
S

SteveB

I am experiencing the same issue as you - just like you say searching for the
field in the header works when recording the macro, but not when you rerun it.

I would love to know if you solved it and how too if you did.

I have about 1000 documents to update (changing fields from time fields to
createdate due to upgrade from word 6 to word 2003) and do not want to have
to do it manually if at all possible.

I will have a look at the article now ! thanks to the person who posted the
link :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top