find and replace field parameter

M

Martin Bozelie

Dear group, I have a question:

I have a number of documents, in which i need to do a find and
replace. There is a field in the header of page 2, with the following
code:

REF Reference \h \* MERGEFORMAT

I want to change it into:

REF Reference \h \* CHARFORMAT.

How do I do this kind of search and replace?

Second problem is, that this field is located in the document header,
and it only becomes visible when people get to page 2! (it is a header
which is not on page one, as set in document settings.)

I would appreciate your input on this one.

regards, Martin
 
G

Graham Mayor

The field bit is irrelevant for this, provided you display the field content
rather than the result (ALT+F9)
You can then replace MERGEFORMAT with CHARFORMAT.
The header adds a further complication :(

The following should do the trick. It looks in the document and headers and
changes all instances of mergeformat to charformat and updates the fields to
reflect the new content.

Dim oStory As Range
Dim oField As Field
ActiveWindow.View.ShowFieldCodes = True
For Each oStory In ActiveDocument.StoryRanges
For Each oField In oStory.Fields
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "MERGEFORMAT"
.Replacement.Text = "CHARFORMAT"
.MatchWildcards = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
oField.Update
Next oField
Next oStory
ActiveWindow.View.ShowFieldCodes = Not ActiveWindow.View.ShowFieldCodes
 

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