Consulting

Results 1 to 5 of 5

Thread: Multiple Find and Replace

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Multiple Find and Replace

    I wrote this macro to find terms and only replace the first occurrence with term and either a registration mark or a trademark. It works beautifully. However, I am still faced with three issues.

    I would like to skip terms that are italicized (done) or in Courier font.

    I would like to include Arial in my search as well, as I will replace the first instance of the word whether it's in Times New Roman or Arial font.

    I would also like to include footnotes in my search. I have seen a few posts on the subject, but none seem to work for me.

    If you have any ideas or solutions, feel free to share. Thank you.

    [vba]
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
    .Text = "Windows"
    .Replacement.Text = "Windows?"
    .Font.Italic = False
    .Font.Name = "Times New Roman"
    .Forward = True
    .Wrap = wdFindStop
    .Format = True
    .MatchCase = True
    .MatchWholeWord = True
    End With
    Selection.Find.Execute
    Selection.GoTo What:=wdGoToSection, Which:=wdGoToFirst, Count:=3, Name:=""
    With Selection
    If .Find.Forward = True Then
    .Collapse Direction:=wdCollapseStart
    Else
    .Collapse Direction:=wdCollapseEnd
    End If
    .Find.Execute Replace:=wdReplaceOne
    If .Find.Forward = True Then
    .Collapse Direction:=wdCollapseEnd
    End If
    .Find.Execute
    End With
    [/vba]

    I need to duplicate this code for each term, so have replaced text with words Bluetooth(R), Proctor & Gamble(R), stuff like that, and am merely using a list of terms in the various fonts (Ariel, Courier and Times New Roman) to conduct the search as it works the same. I have a real document but cannot share here.

    Windows
    Bluetooth
    Proctor & Gamble
    Windows
    Bluetooth
    Proctor & Gamble
    Windows
    Bluetooth
    Proctor & Gamble

    This find and replace starts in the third section of my document, as I want to avoid the cover page and Table of Contents.
    Last edited by thinksalot; 03-04-2006 at 06:55 PM.

Posting Permissions

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