S
singeredel
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!
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!