Re: Help - Find And Replace - one word at a time by Doug
Doug
Thu May 08 02:30:34 PDT 2008
You would then have to do it this way
Dim myrange As Range
Dim Response
Finds = Array("Him", "Mine")
Replaces = Array("Her", "Ours")
For Ndx = LBound(Finds) To UBound(Finds)
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(Findtext:=Finds(Ndx), Forward:=True,
MatchWholeWord:=True, _
MatchCase:=True, MatchWildcards:=False, Wrap:=wdFindStop) =
True
Set myrange = Selection.Range
Response = MsgBox("Do you want to replace " & Finds(Ndx) & "
with " & Replaces(Ndx) & "?", vbYesNo)
If Response = vbYes Then
myrange.Text = Replaces(Ndx)
Else
Selection.Collapse wdCollapseEnd
End If
Loop
End With
Next
--
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
"xxexbushpig" <xxexbushpig@discussions.microsoft.com> wrote in message
news:9376272C-8BF3-4F3D-826A-BC0BEC071D95@microsoft.com...
> Its quite a while since you helped me on this, Tony, so I hope you are
> still
> following this thread and can help me a little further....
>
> The macro works nicely if the word from the FINDS ARRAY that's being
> searched for, still exists somewhere in the document. In that case one can
> click on the "Cancel" button in the Find and Replace window, and the macro
> moves onto the next word in the array. Perfect!
> But, if if the word in the FINDS ARRAY being searched for does not exist
> in
> the document, the "Cancel" button in the Find and Replace window becomes a
> "Close" button. Pressing that causes an error in the macro "Run time
> error
> 5452. "Word has finished searching the document. The search item was not
> found. The macro then can be ended or debugged, but not continued.
> Is there a way to force it to continue?
> Thanks in advance...
> Bushman
>
> Sub WordChange()
> Dim Finds
> Dim Replaces
> Dim ndx
> Finds = Array(" his ", " mine ", " him ", " me ")
> Replaces = Array(" hers ", " ours", " her ", " us ")
> For ndx = LBound(Finds) To UBound(Finds)
> With Dialogs(wdDialogEditReplace)
> .Find = Finds(ndx)
> .Replace = Replaces(ndx)
> .Show
> End With
> Next
> End Sub
>
>
>
>
> "Tony Jollans" wrote:
>
>> When you have finished with one Find you must press Close or Cancel or
>> whatever it takes to end it and then the next one will be started.
>>
>> --
>> Enjoy,
>> Tony
>>
>> "xxexbushpig" <xxexbushpig@discussions.microsoft.com> wrote in message
>> news:A9486B0E-F67A-415F-AA8F-394EEDB7139F@microsoft.com...
>> >I spoke too soon!
>> > The macro starts perfectly, but it does not continue onto the next word
>> > in
>> > the sequence - it just continues with the first word fram the beginning
>> > of
>> > the document again!
>> > Does any one have any ideas, please!
>>
>>