I am trying to write code to find and replace specific text, but I would like
it to stop and highlight each instance and let me select whether or not to
replace each instance, just like it would do in a regular find and replace
text in the document screen. This is what I have so far, but it asks if you
want to make a change but doesn't actually go to the word to be changed, so
you can't see where you are in the document:

ChangePatientToClaimant:
ResponsePatientToClaimant = MsgBox("Do you want to change all instances
of word patient with claimant?", vbYesNo + vbQuestion + vbDefaultButton1,
"ChangePatientToClaimant")
If ResponsePatientToClaimant = vbYes Then
Dim oRng As Range
ResetSearch
Set oRng = ActiveDocument.Content
With oRng.Find
.Text = "patient"
.Replacement.Text = "claimant"
.Forward = True
.Wrap = wdFindContinue
.MatchCase = True
.MatchWholeWord = True
While .Execute
With oRng.Find
FindAction = MsgBox("Make change?", vbYesNo +
vbQuestion + vbDefaultButton1, "Change?")
If FindAction = vbYes Then
.Execute Replace:=wdReplaceOne,
Forward:=True
Else: End
End If
End With
Wend
End With
End If

ResetSearch

Thanks for any help!
--
singeredel

Re: Selective Find & Replace by Helmut

Helmut
Wed Feb 23 07:16:15 CST 2005

Hi,
a matter of taste and style, too.
I prefer simple solutions, like this one:

Dim oRng As Range
ResetSearch
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = "und" ' German for "and"
.Wrap = wdFindContinue
.MatchCase = True
.MatchWholeWord = True
While .Execute
oRng.Select
If MsgBox("Make change?") = vbOK Then
oRng.Text = "oder" ' German for "or"
End If
Wend
End With
ResetSearch
End Sub

By the way, I think, you might be surprised
by what Your code is actually doing.
Cause as far as I see, You execute a find-operation,
and if successful, You execute another find-operation,
and then a replacement, which means, you do the
actual replacement with each second (!) found word.

But I might be wrong and can't test it right now.

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000




Re: Selective Find & Replace by Helmut

Helmut
Wed Feb 23 08:57:22 CST 2005

... and of course,
it's only an example for searching,
stopping and replacing, as it doesn't give
you a choice to say no or to stop it at all.
:-(

It didn' take your code, as there was too much
rearranging form the newsreader format to the VBE.

Hope it helps anyway.

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/




Re: Selective Find & Replace by singeredel

singeredel
Wed Feb 23 09:09:05 CST 2005

Thank you so much! Your version works! I am not surprised that my code
"wanders" as I have no clue what I am doing -- just a lay person trying to
get something done with a lot of trial and error and almost no knowledge. I
like your "simple solutions" -- just finding it hard to get there! :)

"Helmut Weber" wrote:

> Hi,
> a matter of taste and style, too.
> I prefer simple solutions, like this one:
>
> Dim oRng As Range
> ResetSearch
> Set oRng = ActiveDocument.Range
> With oRng.Find
> .Text = "und" ' German for "and"
> .Wrap = wdFindContinue
> .MatchCase = True
> .MatchWholeWord = True
> While .Execute
> oRng.Select
> If MsgBox("Make change?") = vbOK Then
> oRng.Text = "oder" ' German for "or"
> End If
> Wend
> End With
> ResetSearch
> End Sub
>
> By the way, I think, you might be surprised
> by what Your code is actually doing.
> Cause as far as I see, You execute a find-operation,
> and if successful, You execute another find-operation,
> and then a replacement, which means, you do the
> actual replacement with each second (!) found word.
>
> But I might be wrong and can't test it right now.
>
> Greetings from Bavaria, Germany
> Helmut Weber, MVP
> "red.sys" & chr(64) & "t-online.de"
> Word 2002, Windows 2000
>
>
>
>

Re: Selective Find & Replace by singeredel

singeredel
Wed Feb 23 09:57:07 CST 2005

Yes, I "tweaked" it a little. Thanks!

"Helmut Weber" wrote:

> .... and of course,
> it's only an example for searching,
> stopping and replacing, as it doesn't give
> you a choice to say no or to stop it at all.
> :-(
>
> It didn' take your code, as there was too much
> rearranging form the newsreader format to the VBE.
>
> Hope it helps anyway.
>
> Greetings from Bavaria, Germany
>
> Helmut Weber, MVP
> "red.sys" & chr(64) & "t-online.de"
> Word XP, Win 98
> http://word.mvps.org/
>
>
>
>