• find and replace macro

    Author
    Topic
    #408097

    I am looking for a way to write a macro in Word XP that will allow me to use the find and replace tool to change formatting in a document. When I go through the basic record macro steps it does not seem to take the Find and Replace clicks. Any suggestions?

    Viewing 1 reply thread
    Author
    Replies
    • #858673

      It is true, unfortunately, that the macro recorder does not record formatting settings. You will have to write the code yourself.

      Here is an example. Hopefully you can adapt it to your needs:

      With Selection.Find
      .Text = “”
      .Replacement.Text = “”
      .ClearFormatting
      .Replacement.ClearFormatting
      .Forward = True
      .Wrap = wdFindContinue
      .Format = True
      ‘ Look for bold red text
      With .Font
      .Bold = True
      .Color = wdColorRed
      End With
      ‘ Replace with non-bold green text
      With .Replacement.Font
      .Bold = False
      .Color = wdColorGreen
      End With
      .MatchCase = False
      .MatchWholeWord = False
      .MatchWildcards = False
      .MatchSoundsLike = False
      .MatchAllWordForms = False
      .Execute Replace:=wdReplaceAll
      End With

    • #858674

      It is true, unfortunately, that the macro recorder does not record formatting settings. You will have to write the code yourself.

      Here is an example. Hopefully you can adapt it to your needs:

      With Selection.Find
      .Text = “”
      .Replacement.Text = “”
      .ClearFormatting
      .Replacement.ClearFormatting
      .Forward = True
      .Wrap = wdFindContinue
      .Format = True
      ‘ Look for bold red text
      With .Font
      .Bold = True
      .Color = wdColorRed
      End With
      ‘ Replace with non-bold green text
      With .Replacement.Font
      .Bold = False
      .Color = wdColorGreen
      End With
      .MatchCase = False
      .MatchWholeWord = False
      .MatchWildcards = False
      .MatchSoundsLike = False
      .MatchAllWordForms = False
      .Execute Replace:=wdReplaceAll
      End With

    Viewing 1 reply thread
    Reply To: find and replace macro

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: