How do I Find and replace date fields?

G

Guest

Hi,
I have a doc in which date fields were used to indicate when the item /text
was added to the document. I want to find all the date fields and delete
them, without deleting the fields for figures/table and table of contents,
etc... I know I can use Find to find all the fields but I just want to find
and replace / delete the Date Fields.
Thanks,
MK
 
G

Greg Maxey

Provided the fields are in the main text story then this should do:

Sub ScratchMacro2()
Dim oFld As Word.Field
For Each oFld In ActiveDocument.Range.Fields
Select Case oFld.Type
Case Is = wdFieldDate, wdFieldCreateDate, wdFieldSaveDate,
wdFieldPrintDate
oFld.Delete
Case Else
'Do Nothing
End Select
Next oFld
End Sub

If you need to iterate through all storyranges (e.g., headers,
footers, etc) then adapt the code shown here:

http://gregmaxey.mvps.org/Field_Macros.htm
 
G

Greg Maxey

Of course you could just use:

^ d Date

in the find what and replace with nothing

repeat with the other date field types.
 
G

Guest

Thanks Greg,
One minor point to Find Date Fields they need to be visible "Show Fields"
Alt+F9 will show all field codes then the find and replace works great.

Thanks again.
 

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