Consulting

Results 1 to 4 of 4

Thread: Find and Replace in body of document and Footnotes

  1. #1

    Find and Replace in body of document and Footnotes

    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.

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,335
    Location
    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/customizat...ceAnywhere.htm
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    Thanks so much Greg. It worked!

    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
    Last edited by Aussiebear; 04-19-2023 at 04:22 AM. Reason: Adjusted the code tags

  4. #4
    Banned VBAX Newbie
    Joined
    Jun 2023
    Posts
    3
    Location

    bitlife

    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.
    Last edited by davidjohnx; 06-08-2023 at 07:07 PM. Reason: change post content

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •