PDA

View Full Version : [SOLVED:] Find and Replace in body of document and Footnotes



Bernadette
03-15-2012, 11:49 AM
I need to replace all red coloured text with black. When I do a find and replace it finds and replaces everywhere. However, when I record a macro it only finds and replaces in the body of the document and not in the footnotes. I would really appreciate help with this! Thank you.

gmaxey
03-15-2012, 03:54 PM
If you run your macro with the document focus in the footnotes it should work there as well.

When you find and replace with code you have to loop through all of the document story ranges. See: http://word.mvps.org/faqs/customization/ReplaceAnywhere.htm

Bernadette
03-16-2012, 06:26 AM
Thanks so much Greg. It worked! :yes


Sub FindAndReplaceFirstStoryOfEachType()
Dim rngStory As Range
For Each rngStory In ActiveDocument.StoryRanges
With rngStory.Find
.Font.Color = wdColorRed
.Replacement.Font.Color = wdColorAutomatic
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With
Next rngStory
End Sub

davidjohnx
06-08-2023, 07:04 PM
You are correct that when recording a macro, it may only affect the body of the document and not the footnotes. To ensure that the find and replace operation covers all parts of the document, including footnotes, you would need to use VBA code and loop through the various story ranges.