Group: microsoft.public.word.vba.general
From: "fumei via OfficeKB.com"
Date: Tuesday, March 04, 2008 6:38 AM
Subject: Re: A program to find and replace

The 2nd program finds all the words in red and the program replaces them by
the word that I enter. For example, the words "name", "address" and "phone"
are red in a document, and I want to use the 2nd program to find them and
replace them by "John", "England" and "123456" respectively.

You can use an array, if your requirements are that specific.

Dim r As Range
Dim MyReplace()

MyReplace = Array("John", "England", "123456")

Set r = ActiveDocument.Range

With r.Find
.Font.Color = wdColorRed
Do While .Execute(Forward:=True)=True
Select Case r.Text
Case "name"
r.Text = MyReplace(0)
Case "address"
r.Text = MyReplace(1)
Case "phone"
r.Text = MyReplace(2)
End Select
r.Collapse 0
Loop
End With

It will:

search for red text
replace each found red text according to the Select Case

Helmut Weber wrote:
>Hi,
>
>like that:
>
>Sub Test4007()
>Dim rDcm As Range
>Set rDcm = ActiveDocument.Range
>With rDcm.Find
> .Text = "wir" ' german
> .Font.Color = wdColorRed
> .Replacement.Text = "we" ' english
> .Replacement.Font.Color = wdColorBlue
> .Execute Replace:=wdReplaceAll
>End With
>End Sub
>
>Repeat for different words.
>
>--
>
>Greetings from Bavaria, Germany
>
>Helmut Weber, MVP WordVBA
>
>Vista Small Business, Office XP

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-programming/200803/1