S
singeredel
I have code to find and replace strings of text within a document. However, I
get a run-time error "5560" stating the Find What text contains a Pattern
Match expression which is not valid. This is the code:
FindAndReplace:
Dim pFind As String
Dim pReplace As String
Dim pIndex As Long
For pIndex = 1 To 14
pFind = Choose(pIndex, "{Name1}", "{Name2}", "{ClinicAddress}",
"{Date}", "{DOI}", _
"M*.", "*male/female", "*his/her", "*he/she", "*He/She",
"*man/woman", "*gentleman/woman", "*him/her", "*lady/gentleman")
pReplace = Choose(pIndex, PatientFirstName, PatientLastName,
ClinicAddress, ReportDate, DOI, _
Sex1, Sex2, Sex3, Sex4, Sex5, Sex6, Sex7, Sex8, Sex9)
With Selection.Find
.Text = pFind
.Replacement.Text = pReplace
.Forward = True
.Wrap = wdFindContinue
.MatchCase = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
On Error Resume Next
Next
Can anyone tell me what is wrong with this code or possibly another way to
do it? Thanks.
get a run-time error "5560" stating the Find What text contains a Pattern
Match expression which is not valid. This is the code:
FindAndReplace:
Dim pFind As String
Dim pReplace As String
Dim pIndex As Long
For pIndex = 1 To 14
pFind = Choose(pIndex, "{Name1}", "{Name2}", "{ClinicAddress}",
"{Date}", "{DOI}", _
"M*.", "*male/female", "*his/her", "*he/she", "*He/She",
"*man/woman", "*gentleman/woman", "*him/her", "*lady/gentleman")
pReplace = Choose(pIndex, PatientFirstName, PatientLastName,
ClinicAddress, ReportDate, DOI, _
Sex1, Sex2, Sex3, Sex4, Sex5, Sex6, Sex7, Sex8, Sex9)
With Selection.Find
.Text = pFind
.Replacement.Text = pReplace
.Forward = True
.Wrap = wdFindContinue
.MatchCase = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
On Error Resume Next
Next
Can anyone tell me what is wrong with this code or possibly another way to
do it? Thanks.