vba Word 2003 modify headers

T

Tith

I have a macro to run through the document and change all my red text to
blue, but it doesn't affect my headers. How do I get it to incorporate my
headers as well?

Public Sub Red2Blue()
With ActiveDocument.Content.Find
.ClearFormatting
.Font.Color = wdColorRed
With .Replacement
.ClearFormatting
.Font.Color = wdColorBlue
End With

.Execute FindText:="", ReplaceWith:="", Format:=True,
Replace:=wdReplaceAll
End With
End Sub
 
G

Greg Maxey

Unlike the UI Find and Replace operations, your code is only processing the
main text storyrange of the document. At the very least you would need to
interate through the three different header storyranges. This still
wouldn't pick up text in the footers, textboxes, comments, and other
storyranges.

See: http://gregmaxey.mvps.org/VBA_Find_And_Replace.htm
 
T

Tith

Public Sub Red2Blue()
' Replace the headers Text from Red to Blue

Set MyStoryRange = ActiveDocument.StoryRanges(wdPrimaryHeaderStory)
Do Until MyStoryRange Is Nothing

With MyStoryRange.Find
.ClearFormatting
.Font.Color = wdColorRed
With .Replacement
.ClearFormatting
.Font.Color = wdColorBlue
End With

.Execute FindText:="", ReplaceWith:="", Format:=True,
Replace:=wdReplaceAll
End With

Set MyStoryRange = MyStoryRange.NextStoryRange
Loop

' Replace the body Text from Red to Blue
With ActiveDocument.Content.Find
.ClearFormatting
.Font.Color = wdColorRed
With .Replacement
.ClearFormatting
.Font.Color = wdColorBlue
End With

.Execute FindText:="", ReplaceWith:="", Format:=True,
Replace:=wdReplaceAll
End With
End Sub
 

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