Re: Set Range using Find by Helmut
Helmut
Tue Oct 19 03:26:19 CDT 2004
Hi Andrew,
kind of hard to explain all that is to it
here in a few lines. I set up an array of
ranges and redim it for each found question.
Each range in the array (except(0)) gets assigned
the result of find minus 17 letters, the length
of "RESPONSE QUESTION", which is in included in
the result of "find".
Just one of many ways, leaving lots of possibilities
for improvement.
---
Sub Test712()
Dim rFnd As Range
Dim rTmp() As Range
Set rFnd = ActiveDocument.Range
Dim i As Integer
Resetsearch
With rFnd.Find
.Text = "QUESTION*RESPONSE QUESTION"
.MatchWildcards = True
.MatchCase = True
While .Execute
i = i + 1
ReDim Preserve rTmp(i)
Set rTmp(i) = rFnd.Duplicate
rTmp(i).End = rTmp(i).End - 17
Wend
End With
Resetsearch
For i = 1 To UBound(rTmp)
MsgBox rTmp(i)
Next
End Sub
'---
Sub Resetsearch()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute
End With
End Sub
---
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000