Results 1 to 2 of 2
  1. #1
    New Lounger
    Join Date
    May 2004
    Location
    Marshall, Minnesota, USA
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    find and replace macro

    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?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: find and replace macro

    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

Posting Permissions

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