Selecting a Date Field in a Footer to Unlink It

A

Aaron Babel

The following code finds a date field in the
active document and unlinks it, to leave
the current year as text:
...
Selection.GoTo What:=wdGoToField, Name:="Date"
Selection.Fields.Unlink
...

Additionally, the same date field appears in the footer of
the last page of the active document. I wrote this
code to find and unlink it:
...
Selection.GoTo What:=wdGoToPage, Which:=wdGoToLast

With ActiveDocument.ActiveWindow.View
.Type = wdPrintView
.SeekView = wdSeekCurrentPageFooter
End With

Selection.GoTo What:=wdGoToField, Name:="Date"
Selection.Fields.Unlink

However, it doesn't select the fields, and, consequently,
it doesn't unlink it. What am I missing? Or is this simply
not possible?

I hope I've been clear. Thanks for your consideration.

Aaron
 
D

Doug Robbins - Word MVP

Use:

Dim afield As Field
For Each afield In ActiveDocument.Fields
If afield.Type = wdFieldDate Then
afield.Unlink
End If
Next afield


--
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
 
A

Aaron Babel

Much appreciated, Doug.

I've left the "Record Macro" stage about a year ago,
so I'm in that in-between stage of learning how to
optimize my code. Thanks for sharing with me a view
of the "other" side of "General Simplicity." You've been
credited in my code comments.

Aaron
 

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