From: Tith on 10 May 2010 16:02 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
From: Greg Maxey on 10 May 2010 16:22 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 Tith wrote: > 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
From: Tith on 11 May 2010 10:51 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 "Tith" wrote: > 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
|
Pages: 1 Prev: Limitation to Copy/Paste Next: student language tools tab in word 2007 |