Group: microsoft.public.word.vba.general
From: "Doug Robbins - Word MVP"
Date: Thursday, February 28, 2008 4:20 PM
Subject: Re: Selecting Specific Range Within A Document Without Search (Word 2003)

You make use of the Instr() command to determine the amount by which the
.Start of the Range (myrange) must be used and then set the .End of the
Range to the .End of the Range of the Paragraph

Dim myrange As Range
Set myrange = ActiveDocument.Range
myrange.start = myrange.start + InStr(myrange, "MY OTHER SAMPLE WORDS
TO SELECT") + 32
myrange.Start = myrange.start + InStr(myrange, ",")
myrange.End = myrange.Paragraphs(1).Range.End
MsgBox myrange.Text

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Alan Stancliff" wrote in message
news:eLAnICleIHA.4696@TK2MSFTNGP05.phx.gbl...
> Hi Doug (or anybody else willing to help)
>
> You gave me this bit of code:
>
> ********
> Sub Testme()
> Dim myrange As Range
> Set myrange = ActiveDocument.Sections(1).Range
> myrange.start = myrange.start + InStr(myrange, "MY OTHER SAMPLE WORDS
> TO SELECT") + 32
> myrange.End = myrange.start + InStr(myrange, ",") - 1
> MsgBox myrange.Text
> End Sub
> **********
>
> which selects the stuff between the end of the string "MY OTHER SAMPLE
> WORDS TO SELECT" and a comma in a sentence that might look like this:
> (B) MY OTHER SAMPLE WORDS TO SELECT: Hello Universe, So Vast Thou Art.
>
> It works great!
>
> But suppose that I wanted to select the stuff between the comma following
> the string "MY OTHER SAMPLE WORDS TO SELECT" and the end of the line
> (paragraph), and I don't know what's between the end of the string and the
> paragraph mark?
>
> Regards,
>
> Alan Stancliff
>
> Doug Robbins - Word MVP wrote:
>> For the first one use:
>>
>> Dim myrange As Range
>> Set myrange = ActiveDocument.Range
>> myrange.start = myrange.start + InStr(myrange, "MY SAMPLE WORDS TO
>> SELECT:") + 26
>> myrange.End = myrange.Paragraphs(1).Range.End
>> MsgBox myrange.Text
>>
>> and for the second
>>
>> Dim myrange As Range
>> Set myrange = ActiveDocument.Range
>> myrange.start = myrange.start + InStr(myrange, "MY OTHER SAMPLE
>> WORDS TO SELECT") + 32
>> myrange.End = myrange.start + InStr(myrange, ",") - 1
>> MsgBox myrange.Text
>>

Safety Articles | Usenet Groups | Usenet News | Bluegrass