This seems simple but I'm struggling since I've always used selections rather
than ranges. I want to set multiple ranges based on search criteria.

For example, the macro will search for QUESTION 1.1. Then I want to set the
range to be the pargraphs between QUESTION 1.1 and RESPONSE TO QUESTION 1.1.
(Note I want to capture the question, not the response.)

Thanks!

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





Re: Set Range using Find by Andrew

Andrew
Wed Oct 20 22:21:52 CDT 2004

Thanks Helmut. This just the sort of start I was looking for.

"Helmut Weber" wrote:

> 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
>
>
>
>
>