D
Devin Rader
I have a macro that uses the Find object to locate each instance of a
particular Style. When an instance of the Style is found, I would like to
move the cursor to the selection to that I can select the surrounding range
and delete it. The macro is at the end of the message.
Thanks
devin
Dim index As Integer
Dim rngToSrch As Range
Dim rngResult As Range
' Set search ranges
Set rngToSrch = ActiveDocument.Range
Set rngResult = rngToSrch.Duplicate
index = 0
Do
With rngResult.Find
.ClearFormatting
.Style = "InstructorLead"
.Text = ""
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = True
.Execute
End With
' Exit loop if not found
If Not rngResult.Find.Found Then
MsgBox ("No Matches Found")
Exit Do
End If
index = index + 1
' how to move the cursor to the found selection??
' once the cursor is moved, select the surrounding range of text
' delete the selected range
' Prepare for next search by
' moving the start position over one word
rngResult.MoveStart wdWord
' and extending the end of rngResult
rngResult.End = rngToSrch.End
Loop Until Not rngResult.Find.Found
MsgBox ("total matches found: " & index)
particular Style. When an instance of the Style is found, I would like to
move the cursor to the selection to that I can select the surrounding range
and delete it. The macro is at the end of the message.
Thanks
devin
Dim index As Integer
Dim rngToSrch As Range
Dim rngResult As Range
' Set search ranges
Set rngToSrch = ActiveDocument.Range
Set rngResult = rngToSrch.Duplicate
index = 0
Do
With rngResult.Find
.ClearFormatting
.Style = "InstructorLead"
.Text = ""
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = True
.Execute
End With
' Exit loop if not found
If Not rngResult.Find.Found Then
MsgBox ("No Matches Found")
Exit Do
End If
index = index + 1
' how to move the cursor to the found selection??
' once the cursor is moved, select the surrounding range of text
' delete the selected range
' Prepare for next search by
' moving the start position over one word
rngResult.MoveStart wdWord
' and extending the end of rngResult
rngResult.End = rngToSrch.End
Loop Until Not rngResult.Find.Found
MsgBox ("total matches found: " & index)