Macro to unlink in nonprimary header

O

Olympian151

I have written a macro that removes all fields from the document after the
user populates it using dialog boxes (Ask fields). My problem is, I included
coding that unlinked all fields in the header, which I thought was a grand
idea until I realized that it also unlink the Page field!

Is there a way to "protect" the page field so it can not be unlinked when I
run my macro? Or as a fall back, is there a way, using a macro, that I unlink
only the two fields I want unlinked (date and reference number) and leave the
page field intact?

Thanks for any help, I've been searching web but found only global
replacements.
 
G

Graham Mayor

You can conditionally unlink fields eg

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


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
O

Olympian151

thank you Graham!! it worked great with just the littlest modification for
the header and field! I was too focused on just protecting the Page field.
Thank you again!!
 
G

Graham Mayor

You are welcome :)

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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