C
Clueless
I am trying to write code that will search for a word (psychosis for example)
and pause each time the word is found to display a form that will allow the
user to delete the word, sentence or paragraph in which the word resides.
I know how to find the word and I have built the form (not shown) which will
expand the selection and delete as much as the user requests
With Selection.Find
.Text = "psychosis"
.Replacement.Text = ""
.Forward = True
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
But I don't know how to step through the document and pause at each
occurrence of psychosis. An earlier post on this site suggested different
code to find a word but I can't figure out how to use it.
Sub Test()
Dim oRng As Word.Range
Dim oRngDup As Word.Range
Dim oDoc As Document
Set oDoc = ActiveDocument
Set oRng = oDoc.Range
oRng.Start = oDoc.Words(1).Start
oRng.End = oDoc.Words(1).End
Set oRngDup = oRng.Duplicate
With oRng.Find
.Text = oDoc.Words(1).Text
While .Execute
If oRng.End < oRngDup.End Then
oRng.Select
Else
MsgBox "Text not found."
End If
Wend
End With
End Sub
any help is much appreciated!
and pause each time the word is found to display a form that will allow the
user to delete the word, sentence or paragraph in which the word resides.
I know how to find the word and I have built the form (not shown) which will
expand the selection and delete as much as the user requests
With Selection.Find
.Text = "psychosis"
.Replacement.Text = ""
.Forward = True
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
But I don't know how to step through the document and pause at each
occurrence of psychosis. An earlier post on this site suggested different
code to find a word but I can't figure out how to use it.
Sub Test()
Dim oRng As Word.Range
Dim oRngDup As Word.Range
Dim oDoc As Document
Set oDoc = ActiveDocument
Set oRng = oDoc.Range
oRng.Start = oDoc.Words(1).Start
oRng.End = oDoc.Words(1).End
Set oRngDup = oRng.Duplicate
With oRng.Find
.Text = oDoc.Words(1).Text
While .Execute
If oRng.End < oRngDup.End Then
oRng.Select
Else
MsgBox "Text not found."
End If
Wend
End With
End Sub
any help is much appreciated!