Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2005

Tip: Looking for answers? Try searching our database.

Find and Replace

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
singeredel - 18 Mar 2005 18:23 GMT
The purpose of the following code is to find every instance of the word
"patient" and ask whether the word should be changed to "claimaint."
Everything seems to work fine except when "vbNo" is selected. At this point
the program does not cycle to the next instance of the word "patient" but
just continues to remain at the current selection point in a continual loop.
Can anyone tell me what is wrong and what further code may be necessary to
find the next instance of the word "patient?"

Thanks!

ChangePatientToClaimant:
   ResponsePatientToClaimant = MsgBox("Do you want to change instances of
the word 'patient' to 'claimant'?", vbYesNo + vbQuestion + vbDefaultButton1,
"ChangePatientToClaimant")
Dim oRng As Range
   ResetSearch
   Set oRng = ActiveDocument.Range
   With oRng.Find
      .Text = "patient"
      .Wrap = wdFindContinue
      .MatchCase = True
      .MatchWholeWord = True
      While .Execute
         oRng.Select
           ResponseMsgBox = MsgBox("Change 'patient' to 'claimant'?",
vbYesNoCancel + vbQuestion + vbDefaultButton1, "Change")
               If ResponseMsgBox = vbYes Then
                   oRng.Text = "claimant"
               ElseIf ResponseMsgBox = vbNo Then GoTo Continue
               ElseIf ResponseMsgBox = vbCancel Then GoTo DeleteMarks
               End If
Continue:
      Wend
   End With
   ResetSearch

Signature

singeredel (Julie)

Helmut Weber - 18 Mar 2005 18:40 GMT
Hi Julie,
try collapsing the range to it's end in any case.
Means:
if [...] then
  [...]
  rDcm.collapse direction:=wdcollapseend
elseif
  [...]
  rDcm.collapse direction:=wdcollapseend
elseif
  [...]
  rDcm.collapse direction:=wdcollapseend
Endif

Greetings from Bavaria, Germany

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

>The purpose of the following code is to find every instance of the word
>"patient" and ask whether the word should be changed to "claimaint."
[quoted text clipped - 31 lines]
>    End With
>    ResetSearch
singeredel - 18 Mar 2005 19:58 GMT
Hi Helmut,

Thanks again for your help. That indeed moved the selection to the next
incident of the word, but now it is in a continual loop of finding the word
"patient" and never finishes.

> Hi Julie,
> try collapsing the range to it's end in any case.
[quoted text clipped - 52 lines]
> >    End With
> >    ResetSearch
Helmut Weber - 19 Mar 2005 15:07 GMT
Hi Julie,
instead of discussing all, forgive me, mistakes and
logical twists and missing or redunandant code,
I thought, it would be better to start anew.

When using and and select the range,
it might be advisable, to avoid range at all
and use selection from the beginning.

Like this:

Sub test55555()
Dim lRsl As Long    ' Result from Msgbox
Dim sQus As String  ' Question
sQus = "Change 'patient' to 'claimant'?"
' vbYesNo '4
' vbQuestion ' 32
' sum = 36
lRsl = MsgBox(sQus, 36, "Patient to Claimant")

If lRsl = vbNo Then Exit Sub

ResetSearch
With Selection
  .WholeStory
  .Collapse
  With .Find
     .Text = "patient"
     .MatchCase = True
     .MatchWholeWord = True
     While .Execute
        lRsl = MsgBox(sQus, 36, "Change")
        If lRsl = vbYes Then
           Selection.Text = "claimant"
        End If
        Selection.Collapse direction:=wdCollapseEnd
     Wend
  End With
  .WholeStory
  .Collapse
End With
ResetSearch
End Sub

HTH

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
singeredel - 22 Mar 2005 00:27 GMT
Hi Helmut,

Thanks for coming to my rescue again. I have one problem with this code. The
word to be changed is not selected, so I cannot see what word is being
addressed at any particular time. Also, can you explain what "vbYesNo 4" and
"vbQuestion 32", "sum = 36" is about? Thanks.

Julie

> Hi Julie,
> instead of discussing all, forgive me, mistakes and
[quoted text clipped - 48 lines]
> Word XP, Win 98
> http://word.mvps.org/
singeredel - 22 Mar 2005 01:01 GMT
Helmut,

Please ignore my last post regarding not seeing the selection. I see what
has happened. The first message box probably doesn't need to be included.
However, I would still like to know what the 36 is all about in the message
box. Thanks again for your help!

> Hi Julie,
> instead of discussing all, forgive me, mistakes and
[quoted text clipped - 48 lines]
> Word XP, Win 98
> http://word.mvps.org/
Helmut Weber - 22 Mar 2005 04:35 GMT
Hi Julie,

instead of
msgbox [...], vbYesNo + vbQuestion, [...]
you could write
msgbox [...], 4 + 32, [...]
and instead of that you could add the values
msgbox [...], 36, [...]

which makes a single line of code harder to read,
but because of the short lines, I think, the code
altogether is easier to understand.

From my point of view.

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
Helmut Weber - 22 Mar 2005 05:07 GMT
...and besides that all,

note that the messagebox may appear
over the selected word and hide it.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.