Search for text in the header?

R

Roger Marrs

I would like to perform a search and replace for text in the header of an
active document as well as in the body of the active document. I can
perform the search and replace without any problem if the text is body, but
I can't figure out how to use VBA to search the header.

I tried using the macro recorder hoping that would capture the necessary
information, but I couldn't get the macro to function properly using the
information gather from that process.

Here is the code I use to search the body of the document:

Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "-*"
.Replacement.Text = "-"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

I suppose I could delete several of those parameters and the macro would
still work fine.

Thanks in advance for any assistance searching the header.

Roger Marrs
 
R

Roger Marrs

I thought I'd cancelled this post to the group. Now that I've sent the post
again, I see I didn't cancel the message and it posted to the group. Please
disregard this posting as I'm a little more precise in what I'm trying to
accomplish.

Roger
 

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