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