PDA

View Full Version : Trouble with Find and Replace in Word document



debkev1010
08-01-2008, 06:25 AM
I'm using a With statement to find and replace text in a Word document; however, the Found flag is False even when the text is found/replaced -


With currentSrs.Sentences.Item(headingCount).Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "shall [" + vcrmShall
.Replacement.Text = "shall [" + requirementId
.Execute Replace:=1
End With
If (currentSrs.Sentences.Item(headingCount).Find.Found) Then
Exit For
End If

I've declared currentSrs as a Document.

Thanks,
Kevin

mdmackillop
08-02-2008, 03:30 AM
Try

With currentSrs.Sentences.Item(headingCount).Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "shall [" + vcrmShall
.Replacement.Text = "shall [" + requirementId
.Execute Replace:=1
If .Found Then Exit For
End With