Here's a Word 2003 VBA question about RANGEs that's been driving me nuts
for a while.

Supposing I have a document that somewhere has the following on a line
by itself, effectively being a paragraph:

**********
(A) MY SAMPLE WORDS TO SELECT: Hello World

and later on it has a line that has

(B) MY OTHER SAMPLE WORDS TO SELECT: Hello Universe, So Vast Thou Art.
*********

Without using the search functionality, how would one code to do the
following three tasks:
1. Select the the stuff following the colon and two spaces in sample
(A), whatever it may be (in this case, "Hello World")

2. Select the stuff before the comma in my example (B), whatever it may
be (in this case it is Hello Universe)

3 Select the stuff between the comma and end of the line (in this case,
it is "So Vast Thou Art").


Regards,

Alan

Re: Selecting Specific Range Within A Document Without Search (Word 2003) by Tony

Tony
Wed Feb 27 16:00:13 PST 2008

Without using (built-in) search functionality you will have to write your
own - checking each paragraph (using any algorithm you like) until you
identify the one you want.

Having identified the paragraph you can scan it and move the selection
within it using Selection.MoveUntil and Selection.MoveEndUntil and other
similar methods.

--
Enjoy,
Tony

"Alan Stancliff" <alanstancliff@nojunkyahoo.com> wrote in message
news:eDX4fgZeIHA.5400@TK2MSFTNGP04.phx.gbl...
> Here's a Word 2003 VBA question about RANGEs that's been driving me nuts
> for a while.
>
> Supposing I have a document that somewhere has the following on a line by
> itself, effectively being a paragraph:
>
> **********
> (A) MY SAMPLE WORDS TO SELECT: Hello World
>
> and later on it has a line that has
>
> (B) MY OTHER SAMPLE WORDS TO SELECT: Hello Universe, So Vast Thou Art.
> *********
>
> Without using the search functionality, how would one code to do the
> following three tasks:
> 1. Select the the stuff following the colon and two spaces in sample (A),
> whatever it may be (in this case, "Hello World")
>
> 2. Select the stuff before the comma in my example (B), whatever it may be
> (in this case it is Hello Universe)
>
> 3 Select the stuff between the comma and end of the line (in this case, it
> is "So Vast Thou Art").
>
>
> Regards,
>
> Alan


Re: Selecting Specific Range Within A Document Without Search (Word by Alan

Alan
Wed Feb 27 16:42:36 PST 2008

Thanks Tony,

I looked at the help file for Selection.MoveUntil and
Selection.MoveEndUntil.

Unfortunately, I'm pretty much of a beginner at VBA, and I'm not sure
what algorithm to use or how to use it. As you might guess, my question
was a generalization that I devised to help me learn something to help
write a macro. Mostly, what I have been doing is recording and editing
the recorded stuff, while trying to read up on how VBA works.

Do you think it might be possible to give me a few snippits of code that
would do the three tasks I asked about. I would be most grateful.

For anyone looking at this, below my signature line, I am restating the
question in my original post in case you can't see it

Regards,

Alan Stancliff

++++++QUESTION++POSED++++++++++

Supposing I have a document that somewhere has the following on a line
by itself, effectively being a paragraph:

**********
(A) MY SAMPLE WORDS TO SELECT: Hello World

and later on it has a line that has

(B) MY OTHER SAMPLE WORDS TO SELECT: Hello Universe, So Vast Thou Art.
*********

Without using the search functionality, how would one code to do the
following three tasks:
1. Select the the stuff following the colon and two spaces in sample
(A), whatever it may be (in this case, "Hello World")

2. Select the stuff before the comma in my example (B), whatever it may
be (in this case it is Hello Universe)

3 Select the stuff between the comma and end of the line (in this case,
it is "So Vast Thou Art").


Tony Jollans wrote:
> Without using (built-in) search functionality you will have to write
> your own - checking each paragraph (using any algorithm you like) until
> you identify the one you want.
>
> Having identified the paragraph you can scan it and move the selection
> within it using Selection.MoveUntil and Selection.MoveEndUntil and other
> similar methods.
>

Re: Selecting Specific Range Within A Document Without Search (Word 2003) by Jay

Jay
Wed Feb 27 17:18:56 PST 2008

My 2 cents... While Tony's answer is correct, using the search function is MUCH
faster and easier than any other method. If you can think of a good reason not
to use it, I'd like to hear about it.


On Thu, 28 Feb 2008 00:00:13 -0000, "Tony Jollans" <My forename at my surname
dot com> wrote:

>Without using (built-in) search functionality you will have to write your
>own - checking each paragraph (using any algorithm you like) until you
>identify the one you want.
>
>Having identified the paragraph you can scan it and move the selection
>within it using Selection.MoveUntil and Selection.MoveEndUntil and other
>similar methods.
>
>--
>Enjoy,
>Tony
>
>"Alan Stancliff" <alanstancliff@nojunkyahoo.com> wrote in message
>news:eDX4fgZeIHA.5400@TK2MSFTNGP04.phx.gbl...
>> Here's a Word 2003 VBA question about RANGEs that's been driving me nuts
>> for a while.
>>
>> Supposing I have a document that somewhere has the following on a line by
>> itself, effectively being a paragraph:
>>
>> **********
>> (A) MY SAMPLE WORDS TO SELECT: Hello World
>>
>> and later on it has a line that has
>>
>> (B) MY OTHER SAMPLE WORDS TO SELECT: Hello Universe, So Vast Thou Art.
>> *********
>>
>> Without using the search functionality, how would one code to do the
>> following three tasks:
>> 1. Select the the stuff following the colon and two spaces in sample (A),
>> whatever it may be (in this case, "Hello World")
>>
>> 2. Select the stuff before the comma in my example (B), whatever it may be
>> (in this case it is Hello Universe)
>>
>> 3 Select the stuff between the comma and end of the line (in this case, it
>> is "So Vast Thou Art").
>>
>>
>> Regards,
>>
>> Alan

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.

Re: Selecting Specific Range Within A Document Without Search (Word 2003) by Tony

Tony
Wed Feb 27 17:19:56 PST 2008

Hi Alan,

Assuming your cursor is in the right paragraph to begin with (which you'll
have to do separately) then

Selection.Paragraphs(1).Range.Select
Selection.Collapse wdCollapseStart
Selection.MoveUntil ":"
Selection.MoveRight , 3
Selection.MoveEndUntil Chr(13)

will select the paragraph, fall back to the beginning, roll forward to the
colon, then a couple spaces then stretch out to the end.

Of course you would be better not using the selection but that's for another
day :)

Does that help?

--
Enjoy,
Tony

"Alan Stancliff" <alanstancliff@nojunkyahoo.com> wrote in message
news:OfHjZNaeIHA.1208@TK2MSFTNGP05.phx.gbl...
> Thanks Tony,
>
> I looked at the help file for Selection.MoveUntil and
> Selection.MoveEndUntil.
>
> Unfortunately, I'm pretty much of a beginner at VBA, and I'm not sure what
> algorithm to use or how to use it. As you might guess, my question was a
> generalization that I devised to help me learn something to help write a
> macro. Mostly, what I have been doing is recording and editing the
> recorded stuff, while trying to read up on how VBA works.
>
> Do you think it might be possible to give me a few snippits of code that
> would do the three tasks I asked about. I would be most grateful.
>
> For anyone looking at this, below my signature line, I am restating the
> question in my original post in case you can't see it
>
> Regards,
>
> Alan Stancliff
>
> ++++++QUESTION++POSED++++++++++
>
> Supposing I have a document that somewhere has the following on a line by
> itself, effectively being a paragraph:
>
> **********
> (A) MY SAMPLE WORDS TO SELECT: Hello World
>
> and later on it has a line that has
>
> (B) MY OTHER SAMPLE WORDS TO SELECT: Hello Universe, So Vast Thou Art.
> *********
>
> Without using the search functionality, how would one code to do the
> following three tasks:
> 1. Select the the stuff following the colon and two spaces in sample (A),
> whatever it may be (in this case, "Hello World")
>
> 2. Select the stuff before the comma in my example (B), whatever it may be
> (in this case it is Hello Universe)
>
> 3 Select the stuff between the comma and end of the line (in this case, it
> is "So Vast Thou Art").
>
>
> Tony Jollans wrote:
>> Without using (built-in) search functionality you will have to write your
>> own - checking each paragraph (using any algorithm you like) until you
>> identify the one you want.
>>
>> Having identified the paragraph you can scan it and move the selection
>> within it using Selection.MoveUntil and Selection.MoveEndUntil and other
>> similar methods.
>>


Re: Selecting Specific Range Within A Document Without Search (Word by Alan

Alan
Wed Feb 27 17:28:04 PST 2008

Hi Jay,

Yes, I was hoping to avoid the screen from jumping around during the
performance of this task. I actually got the idea for the question by
studying an exchange of messages we had last month, which you can refer
to here:

Browser link:
http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.word.vba.general&tid=0e7336bb-59cf-4e33-99c8-c431abd8ef12&cat=en_US_eb67b351-9403-4888-a42c-b2b58efec0aa&lang=en&cr=US&sloc=en-us&m=1&p=1

Newsreader link:
news://msnews.microsoft.com:119/0E7336BB-59CF-4E33-99C8-C431ABD8EF12@microsoft.com

Regards,

Alan Stancliff


Jay Freedman wrote:
> My 2 cents... While Tony's answer is correct, using the search function is MUCH
> faster and easier than any other method. If you can think of a good reason not
> to use it, I'd like to hear about it.
>
>
> On Thu, 28 Feb 2008 00:00:13 -0000, "Tony Jollans" <My forename at my surname
> dot com> wrote:
>
>> Without using (built-in) search functionality you will have to write your
>> own - checking each paragraph (using any algorithm you like) until you
>> identify the one you want.
>>
>> Having identified the paragraph you can scan it and move the selection
>> within it using Selection.MoveUntil and Selection.MoveEndUntil and other
>> similar methods.
>>
>> --
>> Enjoy,
>> Tony
>>
>> "Alan Stancliff" <alanstancliff@nojunkyahoo.com> wrote in message
>> news:eDX4fgZeIHA.5400@TK2MSFTNGP04.phx.gbl...
>>> Here's a Word 2003 VBA question about RANGEs that's been driving me nuts
>>> for a while.
>>>
>>> Supposing I have a document that somewhere has the following on a line by
>>> itself, effectively being a paragraph:
>>>
>>> **********
>>> (A) MY SAMPLE WORDS TO SELECT: Hello World
>>>
>>> and later on it has a line that has
>>>
>>> (B) MY OTHER SAMPLE WORDS TO SELECT: Hello Universe, So Vast Thou Art.
>>> *********
>>>
>>> Without using the search functionality, how would one code to do the
>>> following three tasks:
>>> 1. Select the the stuff following the colon and two spaces in sample (A),
>>> whatever it may be (in this case, "Hello World")
>>>
>>> 2. Select the stuff before the comma in my example (B), whatever it may be
>>> (in this case it is Hello Universe)
>>>
>>> 3 Select the stuff between the comma and end of the line (in this case, it
>>> is "So Vast Thou Art").
>>>
>>>
>>> Regards,
>>>
>>> Alan
>
> --
> Regards,
> Jay Freedman
> Microsoft Word MVP FAQ: http://word.mvps.org
> Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.

Re: Selecting Specific Range Within A Document Without Search (Word 2003) by Greg

Greg
Wed Feb 27 18:44:38 PST 2008

I don't know. Something like this:

Sub ScratchmacroI()
Dim oPara As Paragraph
For Each oPara In ActiveDocument.Range.Paragraphs
If Left(oPara.Range.Text, Len(oPara.Range.Text) - 1) Like "MY SAMPLE WORDS
TO SELECT: Hello World" Then
oPara.Range.Select
With Selection
.MoveStartUntil ":", wdForward
.MoveStart wdCharacter, 3
Exit Sub
End With
End If
Next
End Sub
Sub ScratchmacroII()
Dim oPara As Paragraph
For Each oPara In ActiveDocument.Range.Paragraphs
If Left(oPara.Range.Text, Len(oPara.Range.Text) - 1) Like "MY OTHER SAMPLE
WORDS TO SELECT: Hello Universe, So Vast Thou Art." Then
oPara.Range.Select
With Selection
.MoveStartUntil ":", wdForward
.MoveStart wdCharacter, 3
.MoveEndUntil ",", wdBackward
.MoveEnd wdCharacter, -1
Exit Sub
End With
End If
Next
End Sub
Sub ScratchmacroIII()
Dim oPara As Paragraph
For Each oPara In ActiveDocument.Range.Paragraphs
If Left(oPara.Range.Text, Len(oPara.Range.Text) - 1) Like "MY OTHER SAMPLE
WORDS TO SELECT: Hello Universe, So Vast Thou Art." Then
oPara.Range.Select
With Selection
.Collapse wdCollapseEnd
.MoveStartUntil ",", wdBackward
.MoveStart wdCharacter, 1
Exit Sub
End With
End If
Next
End Sub


--
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Greg Maxey - Word MVP

My web site http://gregmaxey.mvps.org
Word MVP web site http://word.mvps.org
~~~~~~~~~~~~~~~~~~~~~~~~~~~~



Alan Stancliff wrote:
> Thanks Tony,
>
> I looked at the help file for Selection.MoveUntil and
> Selection.MoveEndUntil.
>
> Unfortunately, I'm pretty much of a beginner at VBA, and I'm not sure
> what algorithm to use or how to use it. As you might guess, my
> question was a generalization that I devised to help me learn
> something to help write a macro. Mostly, what I have been doing is
> recording and editing the recorded stuff, while trying to read up on
> how VBA works.
> Do you think it might be possible to give me a few snippits of code
> that would do the three tasks I asked about. I would be most grateful.
>
> For anyone looking at this, below my signature line, I am restating
> the question in my original post in case you can't see it
>
> Regards,
>
> Alan Stancliff
>
> ++++++QUESTION++POSED++++++++++
>
> Supposing I have a document that somewhere has the following on a line
> by itself, effectively being a paragraph:
>
> **********
> (A) MY SAMPLE WORDS TO SELECT: Hello World
>
> and later on it has a line that has
>
> (B) MY OTHER SAMPLE WORDS TO SELECT: Hello Universe, So Vast Thou Art.
> *********
>
> Without using the search functionality, how would one code to do the
> following three tasks:
> 1. Select the the stuff following the colon and two spaces in sample
> (A), whatever it may be (in this case, "Hello World")
>
> 2. Select the stuff before the comma in my example (B), whatever it
> may be (in this case it is Hello Universe)
>
> 3 Select the stuff between the comma and end of the line (in this
> case, it is "So Vast Thou Art").
>
>
> Tony Jollans wrote:
>> Without using (built-in) search functionality you will have to write
>> your own - checking each paragraph (using any algorithm you like)
>> until you identify the one you want.
>>
>> Having identified the paragraph you can scan it and move the
>> selection within it using Selection.MoveUntil and
>> Selection.MoveEndUntil and other similar methods.



Re: Selecting Specific Range Within A Document Without Search (Word 2003) by Jay

Jay
Wed Feb 27 19:43:33 PST 2008

Hi Alan,

If you use a Range object instead of the Selection, as in the demo() sample in
the posts you pointed to, then the screen won't jump at all. The problem you're
having is largely that the macro recorder always uses the Selection -- one of
its more serious drawbacks.

On Wed, 27 Feb 2008 17:28:04 -0800, Alan Stancliff
<alanstancliff@nojunkyahoo.com> wrote:

>Hi Jay,
>
>Yes, I was hoping to avoid the screen from jumping around during the
>performance of this task. I actually got the idea for the question by
>studying an exchange of messages we had last month, which you can refer
>to here:
>
>Browser link:
>http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.word.vba.general&tid=0e7336bb-59cf-4e33-99c8-c431abd8ef12&cat=en_US_eb67b351-9403-4888-a42c-b2b58efec0aa&lang=en&cr=US&sloc=en-us&m=1&p=1
>
>Newsreader link:
>news://msnews.microsoft.com:119/0E7336BB-59CF-4E33-99C8-C431ABD8EF12@microsoft.com
>
>Regards,
>
>Alan Stancliff
>
>
>Jay Freedman wrote:
>> My 2 cents... While Tony's answer is correct, using the search function is MUCH
>> faster and easier than any other method. If you can think of a good reason not
>> to use it, I'd like to hear about it.
>>
>>
>> On Thu, 28 Feb 2008 00:00:13 -0000, "Tony Jollans" <My forename at my surname
>> dot com> wrote:
>>
>>> Without using (built-in) search functionality you will have to write your
>>> own - checking each paragraph (using any algorithm you like) until you
>>> identify the one you want.
>>>
>>> Having identified the paragraph you can scan it and move the selection
>>> within it using Selection.MoveUntil and Selection.MoveEndUntil and other
>>> similar methods.
>>>
>>> --
>>> Enjoy,
>>> Tony
>>>
>>> "Alan Stancliff" <alanstancliff@nojunkyahoo.com> wrote in message
>>> news:eDX4fgZeIHA.5400@TK2MSFTNGP04.phx.gbl...
>>>> Here's a Word 2003 VBA question about RANGEs that's been driving me nuts
>>>> for a while.
>>>>
>>>> Supposing I have a document that somewhere has the following on a line by
>>>> itself, effectively being a paragraph:
>>>>
>>>> **********
>>>> (A) MY SAMPLE WORDS TO SELECT: Hello World
>>>>
>>>> and later on it has a line that has
>>>>
>>>> (B) MY OTHER SAMPLE WORDS TO SELECT: Hello Universe, So Vast Thou Art.
>>>> *********
>>>>
>>>> Without using the search functionality, how would one code to do the
>>>> following three tasks:
>>>> 1. Select the the stuff following the colon and two spaces in sample (A),
>>>> whatever it may be (in this case, "Hello World")
>>>>
>>>> 2. Select the stuff before the comma in my example (B), whatever it may be
>>>> (in this case it is Hello Universe)
>>>>
>>>> 3 Select the stuff between the comma and end of the line (in this case, it
>>>> is "So Vast Thou Art").
>>>>
>>>>
>>>> Regards,
>>>>
>>>> Alan
>>
>> --
>> Regards,
>> Jay Freedman
>> Microsoft Word MVP FAQ: http://word.mvps.org
>> Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.

Re: Selecting Specific Range Within A Document Without Search (Word by Alan

Alan
Thu Feb 28 00:32:09 PST 2008


Hi Jay,

You wrote:
*********
If you use a Range object instead of the Selection, as in the demo()
sample in
the posts you pointed to, then the screen won't jump at all. The problem
you're
having is largely that the macro recorder always uses the Selection --
one of
its more serious drawbacks.
*******

I've been spending several hours, actually much more than that if I
count the time I've spent during the last month trying to conceptualize
the problem, formulate it specifically, pose it intelligently, look at
the answers carefully, and experiment and research. In studying previous
posts, especially the one with your demo routine, I have come up against
a rather frustrating brick wall. I hope I can get this resolved as my
wife's patience is wearing thin.

I decided to record the tasks and then substitute the Range Object for
the Selection Object.

Here's how I can do the first task with a recorded macro:

Sub Eraseme()
Selection.Find.ClearFormatting
With Selection.Find
.Text = "MY SAMPLE WORDS TO SELECT:"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdWord, Count:=1
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
End Sub



Here is my latest of 14 gazillion attempts to use Range Object instead
of the Selection Object. It falls apart and I don't know why.

Sub Eraseme()
Dim oRg As Range
Set oRg = ActiveDocument.Range
With oRg.Find
.Text = "MY SAMPLE WORDS TO SELECT:"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
range.find.execute
Selection.MoveRight Unit:=wdWord, Count:=1
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
End Sub

Here is how I could accomplish the second sample question with a
recorded macro. This throws in the element of wildcards. How could I
substitute the use of the Range Object instead?

Sub eraseme()

Selection.Find.ClearFormatting
With Selection.Find
.Text = "MY OTHER SAMPLE WORDS TO SELECT:"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdWord, Count:=1
Selection.Find.ClearFormatting
With Selection.Find
.Text = "*,"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
End Sub

My purpose is to assign the selected items to either an Autocorrect
Entries or a variables in several macros.

Please, someone just show me how to substitute the Range Object for the
Selection Object in these. I really would be most grateful for the help.
Moreover, it would really help me understand more about VBA.

Regards,

Alan Stancliff

****************************************
Jay Freedman wrote:
> Hi Alan,
>
> If you use a Range object instead of the Selection, as in the demo() sample in
> the posts you pointed to, then the screen won't jump at all. The problem you're
> having is largely that the macro recorder always uses the Selection -- one of
> its more serious drawbacks.
>
> On Wed, 27 Feb 2008 17:28:04 -0800, Alan Stancliff
> <alanstancliff@nojunkyahoo.com> wrote:
>
>> Hi Jay,
>>
>> Yes, I was hoping to avoid the screen from jumping around during the
>> performance of this task. I actually got the idea for the question by
>> studying an exchange of messages we had last month, which you can refer
>> to here:
>>
>> Browser link:
>> http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.word.vba.general&tid=0e7336bb-59cf-4e33-99c8-c431abd8ef12&cat=en_US_eb67b351-9403-4888-a42c-b2b58efec0aa&lang=en&cr=US&sloc=en-us&m=1&p=1
>>
>> Newsreader link:
>> news://msnews.microsoft.com:119/0E7336BB-59CF-4E33-99C8-C431ABD8EF12@microsoft.com
>>
>> Regards,
>>
>> Alan Stancliff
>>
>>
>> Jay Freedman wrote:
>>> My 2 cents... While Tony's answer is correct, using the search function is MUCH
>>> faster and easier than any other method. If you can think of a good reason not
>>> to use it, I'd like to hear about it.
>>>
>>>
>>> On Thu, 28 Feb 2008 00:00:13 -0000, "Tony Jollans" <My forename at my surname
>>> dot com> wrote:
>>>
>>>> Without using (built-in) search functionality you will have to write your
>>>> own - checking each paragraph (using any algorithm you like) until you
>>>> identify the one you want.
>>>>
>>>> Having identified the paragraph you can scan it and move the selection
>>>> within it using Selection.MoveUntil and Selection.MoveEndUntil and other
>>>> similar methods.
>>>>
>>>> --
>>>> Enjoy,
>>>> Tony
>>>>
>>>> "Alan Stancliff" <alanstancliff@nojunkyahoo.com> wrote in message
>>>> news:eDX4fgZeIHA.5400@TK2MSFTNGP04.phx.gbl...
>>>>> Here's a Word 2003 VBA question about RANGEs that's been driving me nuts
>>>>> for a while.
>>>>>
>>>>> Supposing I have a document that somewhere has the following on a line by
>>>>> itself, effectively being a paragraph:
>>>>>
>>>>> **********
>>>>> (A) MY SAMPLE WORDS TO SELECT: Hello World
>>>>>
>>>>> and later on it has a line that has
>>>>>
>>>>> (B) MY OTHER SAMPLE WORDS TO SELECT: Hello Universe, So Vast Thou Art.
>>>>> *********
>>>>>
>>>>> Without using the search functionality, how would one code to do the
>>>>> following three tasks:
>>>>> 1. Select the the stuff following the colon and two spaces in sample (A),
>>>>> whatever it may be (in this case, "Hello World")
>>>>>
>>>>> 2. Select the stuff before the comma in my example (B), whatever it may be
>>>>> (in this case it is Hello Universe)
>>>>>
>>>>> 3 Select the stuff between the comma and end of the line (in this case, it
>>>>> is "So Vast Thou Art").
>>>>>
>>>>>
>>>>> Regards,
>>>>>
>>>>> Alan
>>> --
>>> Regards,
>>> Jay Freedman
>>> Microsoft Word MVP FAQ: http://word.mvps.org
>>> Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.
>
> --
> Regards,
> Jay Freedman
> Microsoft Word MVP FAQ: http://word.mvps.org
> Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.

Re: Selecting Specific Range Within A Document Without Search (Word 2003) by Doug

Doug
Thu Feb 28 01:29:15 PST 2008

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


--
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" <alanstancliff@nojunkyahoo.com> wrote in message
news:uSwGLSeeIHA.4140@TK2MSFTNGP04.phx.gbl...
>
> Hi Jay,
>
> You wrote:
> *********
> If you use a Range object instead of the Selection, as in the demo()
> sample in
> the posts you pointed to, then the screen won't jump at all. The problem
> you're
> having is largely that the macro recorder always uses the Selection --
> one of
> its more serious drawbacks.
> *******
>
> I've been spending several hours, actually much more than that if I count
> the time I've spent during the last month trying to conceptualize the
> problem, formulate it specifically, pose it intelligently, look at the
> answers carefully, and experiment and research. In studying previous
> posts, especially the one with your demo routine, I have come up against a
> rather frustrating brick wall. I hope I can get this resolved as my wife's
> patience is wearing thin.
>
> I decided to record the tasks and then substitute the Range Object for the
> Selection Object.
>
> Here's how I can do the first task with a recorded macro:
>
> Sub Eraseme()
> Selection.Find.ClearFormatting
> With Selection.Find
> .Text = "MY SAMPLE WORDS TO SELECT:"
> .Replacement.Text = ""
> .Forward = True
> .Wrap = wdFindContinue
> .Format = False
> .MatchCase = False
> .MatchWholeWord = False
> .MatchWildcards = False
> .MatchSoundsLike = False
> .MatchAllWordForms = False
> End With
> Selection.Find.Execute
> Selection.MoveRight Unit:=wdWord, Count:=1
> Selection.EndKey Unit:=wdLine, Extend:=wdExtend
> Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
> End Sub
>
>
>
> Here is my latest of 14 gazillion attempts to use Range Object instead of
> the Selection Object. It falls apart and I don't know why.
>
> Sub Eraseme()
> Dim oRg As Range
> Set oRg = ActiveDocument.Range
> With oRg.Find
> .Text = "MY SAMPLE WORDS TO SELECT:"
> .Replacement.Text = ""
> .Forward = True
> .Wrap = wdFindContinue
> .Format = False
> .MatchCase = False
> .MatchWholeWord = False
> .MatchWildcards = False
> .MatchSoundsLike = False
> .MatchAllWordForms = False
> End With
> range.find.execute
> Selection.MoveRight Unit:=wdWord, Count:=1
> Selection.EndKey Unit:=wdLine, Extend:=wdExtend
> Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
> End Sub
>
> Here is how I could accomplish the second sample question with a recorded
> macro. This throws in the element of wildcards. How could I substitute the
> use of the Range Object instead?
>
> Sub eraseme()
>
> Selection.Find.ClearFormatting
> With Selection.Find
> .Text = "MY OTHER SAMPLE WORDS TO SELECT:"
> .Replacement.Text = ""
> .Forward = True
> .Wrap = wdFindContinue
> .Format = False
> .MatchCase = False
> .MatchWholeWord = False
> .MatchWildcards = False
> .MatchSoundsLike = False
> .MatchAllWordForms = False
> End With
> Selection.Find.Execute
> Selection.MoveRight Unit:=wdWord, Count:=1
> Selection.Find.ClearFormatting
> With Selection.Find
> .Text = "*,"
> .Replacement.Text = ""
> .Forward = True
> .Wrap = wdFindContinue
> .Format = False
> .MatchCase = False
> .MatchWholeWord = False
> .MatchAllWordForms = False
> .MatchSoundsLike = False
> .MatchWildcards = True
> End With
> Selection.Find.Execute
> End Sub
>
> My purpose is to assign the selected items to either an Autocorrect
> Entries or a variables in several macros.
>
> Please, someone just show me how to substitute the Range Object for the
> Selection Object in these. I really would be most grateful for the help.
> Moreover, it would really help me understand more about VBA.
>
> Regards,
>
> Alan Stancliff
>
> ****************************************
> Jay Freedman wrote:
>> Hi Alan,
>>
>> If you use a Range object instead of the Selection, as in the demo()
>> sample in
>> the posts you pointed to, then the screen won't jump at all. The problem
>> you're
>> having is largely that the macro recorder always uses the Selection --
>> one of
>> its more serious drawbacks. On Wed, 27 Feb 2008 17:28:04 -0800, Alan
>> Stancliff
>> <alanstancliff@nojunkyahoo.com> wrote:
>>
>>> Hi Jay,
>>>
>>> Yes, I was hoping to avoid the screen from jumping around during the
>>> performance of this task. I actually got the idea for the question by
>>> studying an exchange of messages we had last month, which you can refer
>>> to here:
>>>
>>> Browser link:
>>> http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.word.vba.general&tid=0e7336bb-59cf-4e33-99c8-c431abd8ef12&cat=en_US_eb67b351-9403-4888-a42c-b2b58efec0aa&lang=en&cr=US&sloc=en-us&m=1&p=1
>>>
>>> Newsreader link:
>>> news://msnews.microsoft.com:119/0E7336BB-59CF-4E33-99C8-C431ABD8EF12@microsoft.com
>>>
>>> Regards,
>>>
>>> Alan Stancliff
>>>
>>>
>>> Jay Freedman wrote:
>>>> My 2 cents... While Tony's answer is correct, using the search function
>>>> is MUCH
>>>> faster and easier than any other method. If you can think of a good
>>>> reason not
>>>> to use it, I'd like to hear about it.
>>>>
>>>>
>>>> On Thu, 28 Feb 2008 00:00:13 -0000, "Tony Jollans" <My forename at my
>>>> surname
>>>> dot com> wrote:
>>>>
>>>>> Without using (built-in) search functionality you will have to write
>>>>> your own - checking each paragraph (using any algorithm you like)
>>>>> until you identify the one you want.
>>>>>
>>>>> Having identified the paragraph you can scan it and move the selection
>>>>> within it using Selection.MoveUntil and Selection.MoveEndUntil and
>>>>> other similar methods.
>>>>>
>>>>> --
>>>>> Enjoy,
>>>>> Tony
>>>>>
>>>>> "Alan Stancliff" <alanstancliff@nojunkyahoo.com> wrote in message
>>>>> news:eDX4fgZeIHA.5400@TK2MSFTNGP04.phx.gbl...
>>>>>> Here's a Word 2003 VBA question about RANGEs that's been driving me
>>>>>> nuts for a while.
>>>>>>
>>>>>> Supposing I have a document that somewhere has the following on a
>>>>>> line by itself, effectively being a paragraph:
>>>>>>
>>>>>> **********
>>>>>> (A) MY SAMPLE WORDS TO SELECT: Hello World
>>>>>>
>>>>>> and later on it has a line that has
>>>>>>
>>>>>> (B) MY OTHER SAMPLE WORDS TO SELECT: Hello Universe, So Vast Thou
>>>>>> Art.
>>>>>> *********
>>>>>>
>>>>>> Without using the search functionality, how would one code to do the
>>>>>> following three tasks:
>>>>>> 1. Select the the stuff following the colon and two spaces in sample
>>>>>> (A), whatever it may be (in this case, "Hello World")
>>>>>>
>>>>>> 2. Select the stuff before the comma in my example (B), whatever it
>>>>>> may be (in this case it is Hello Universe)
>>>>>>
>>>>>> 3 Select the stuff between the comma and end of the line (in this
>>>>>> case, it is "So Vast Thou Art").
>>>>>>
>>>>>>
>>>>>> Regards,
>>>>>>
>>>>>> Alan
>>>> --
>>>> Regards,
>>>> Jay Freedman
>>>> Microsoft Word MVP FAQ: http://word.mvps.org
>>>> Email cannot be acknowledged; please post all follow-ups to the
>>>> newsgroup so all may benefit.
>>
>> --
>> Regards,
>> Jay Freedman
>> Microsoft Word MVP FAQ: http://word.mvps.org
>> Email cannot be acknowledged; please post all follow-ups to the newsgroup
>> so all may benefit.



Re: Selecting Specific Range Within A Document Without Search (Word 2003) by Tony

Tony
Thu Feb 28 02:30:26 PST 2008

1. You set up the Find object belonging to the oRg object. You must then
execute the same Find object, so ...

oRg.Find.execute

Having done that you must then manipulate oRg instead of Selection.

2. Again, set up a range and then substitute it for Selection.

--
Enjoy,
Tony

"Alan Stancliff" <alanstancliff@nojunkyahoo.com> wrote in message
news:uSwGLSeeIHA.4140@TK2MSFTNGP04.phx.gbl...
>
> Hi Jay,
>
> You wrote:
> *********
> If you use a Range object instead of the Selection, as in the demo()
> sample in
> the posts you pointed to, then the screen won't jump at all. The problem
> you're
> having is largely that the macro recorder always uses the Selection --
> one of
> its more serious drawbacks.
> *******
>
> I've been spending several hours, actually much more than that if I count
> the time I've spent during the last month trying to conceptualize the
> problem, formulate it specifically, pose it intelligently, look at the
> answers carefully, and experiment and research. In studying previous
> posts, especially the one with your demo routine, I have come up against a
> rather frustrating brick wall. I hope I can get this resolved as my wife's
> patience is wearing thin.
>
> I decided to record the tasks and then substitute the Range Object for the
> Selection Object.
>
> Here's how I can do the first task with a recorded macro:
>
> Sub Eraseme()
> Selection.Find.ClearFormatting
> With Selection.Find
> .Text = "MY SAMPLE WORDS TO SELECT:"
> .Replacement.Text = ""
> .Forward = True
> .Wrap = wdFindContinue
> .Format = False
> .MatchCase = False
> .MatchWholeWord = False
> .MatchWildcards = False
> .MatchSoundsLike = False
> .MatchAllWordForms = False
> End With
> Selection.Find.Execute
> Selection.MoveRight Unit:=wdWord, Count:=1
> Selection.EndKey Unit:=wdLine, Extend:=wdExtend
> Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
> End Sub
>
>
>
> Here is my latest of 14 gazillion attempts to use Range Object instead of
> the Selection Object. It falls apart and I don't know why.
>
> Sub Eraseme()
> Dim oRg As Range
> Set oRg = ActiveDocument.Range
> With oRg.Find
> .Text = "MY SAMPLE WORDS TO SELECT:"
> .Replacement.Text = ""
> .Forward = True
> .Wrap = wdFindContinue
> .Format = False
> .MatchCase = False
> .MatchWholeWord = False
> .MatchWildcards = False
> .MatchSoundsLike = False
> .MatchAllWordForms = False
> End With
> range.find.execute
> Selection.MoveRight Unit:=wdWord, Count:=1
> Selection.EndKey Unit:=wdLine, Extend:=wdExtend
> Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
> End Sub
>
> Here is how I could accomplish the second sample question with a recorded
> macro. This throws in the element of wildcards. How could I substitute the
> use of the Range Object instead?
>
> Sub eraseme()
>
> Selection.Find.ClearFormatting
> With Selection.Find
> .Text = "MY OTHER SAMPLE WORDS TO SELECT:"
> .Replacement.Text = ""
> .Forward = True
> .Wrap = wdFindContinue
> .Format = False
> .MatchCase = False
> .MatchWholeWord = False
> .MatchWildcards = False
> .MatchSoundsLike = False
> .MatchAllWordForms = False
> End With
> Selection.Find.Execute
> Selection.MoveRight Unit:=wdWord, Count:=1
> Selection.Find.ClearFormatting
> With Selection.Find
> .Text = "*,"
> .Replacement.Text = ""
> .Forward = True
> .Wrap = wdFindContinue
> .Format = False
> .MatchCase = False
> .MatchWholeWord = False
> .MatchAllWordForms = False
> .MatchSoundsLike = False
> .MatchWildcards = True
> End With
> Selection.Find.Execute
> End Sub
>
> My purpose is to assign the selected items to either an Autocorrect
> Entries or a variables in several macros.
>
> Please, someone just show me how to substitute the Range Object for the
> Selection Object in these. I really would be most grateful for the help.
> Moreover, it would really help me understand more about VBA.
>
> Regards,
>
> Alan Stancliff
>
> ****************************************
> Jay Freedman wrote:
>> Hi Alan,
>>
>> If you use a Range object instead of the Selection, as in the demo()
>> sample in
>> the posts you pointed to, then the screen won't jump at all. The problem
>> you're
>> having is largely that the macro recorder always uses the Selection --
>> one of
>> its more serious drawbacks. On Wed, 27 Feb 2008 17:28:04 -0800, Alan
>> Stancliff
>> <alanstancliff@nojunkyahoo.com> wrote:
>>
>>> Hi Jay,
>>>
>>> Yes, I was hoping to avoid the screen from jumping around during the
>>> performance of this task. I actually got the idea for the question by
>>> studying an exchange of messages we had last month, which you can refer
>>> to here:
>>>
>>> Browser link:
>>> http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.word.vba.general&tid=0e7336bb-59cf-4e33-99c8-c431abd8ef12&cat=en_US_eb67b351-9403-4888-a42c-b2b58efec0aa&lang=en&cr=US&sloc=en-us&m=1&p=1
>>>
>>> Newsreader link:
>>> news://msnews.microsoft.com:119/0E7336BB-59CF-4E33-99C8-C431ABD8EF12@microsoft.com
>>>
>>> Regards,
>>>
>>> Alan Stancliff
>>>
>>>
>>> Jay Freedman wrote:
>>>> My 2 cents... While Tony's answer is correct, using the search function
>>>> is MUCH
>>>> faster and easier than any other method. If you can think of a good
>>>> reason not
>>>> to use it, I'd like to hear about it.
>>>>
>>>>
>>>> On Thu, 28 Feb 2008 00:00:13 -0000, "Tony Jollans" <My forename at my
>>>> surname
>>>> dot com> wrote:
>>>>
>>>>> Without using (built-in) search functionality you will have to write
>>>>> your own - checking each paragraph (using any algorithm you like)
>>>>> until you identify the one you want.
>>>>>
>>>>> Having identified the paragraph you can scan it and move the selection
>>>>> within it using Selection.MoveUntil and Selection.MoveEndUntil and
>>>>> other similar methods.
>>>>>
>>>>> --
>>>>> Enjoy,
>>>>> Tony
>>>>>
>>>>> "Alan Stancliff" <alanstancliff@nojunkyahoo.com> wrote in message
>>>>> news:eDX4fgZeIHA.5400@TK2MSFTNGP04.phx.gbl...
>>>>>> Here's a Word 2003 VBA question about RANGEs that's been driving me
>>>>>> nuts for a while.
>>>>>>
>>>>>> Supposing I have a document that somewhere has the following on a
>>>>>> line by itself, effectively being a paragraph:
>>>>>>
>>>>>> **********
>>>>>> (A) MY SAMPLE WORDS TO SELECT: Hello World
>>>>>>
>>>>>> and later on it has a line that has
>>>>>>
>>>>>> (B) MY OTHER SAMPLE WORDS TO SELECT: Hello Universe, So Vast Thou
>>>>>> Art.
>>>>>> *********
>>>>>>
>>>>>> Without using the search functionality, how would one code to do the
>>>>>> following three tasks:
>>>>>> 1. Select the the stuff following the colon and two spaces in sample
>>>>>> (A), whatever it may be (in this case, "Hello World")
>>>>>>
>>>>>> 2. Select the stuff before the comma in my example (B), whatever it
>>>>>> may be (in this case it is Hello Universe)
>>>>>>
>>>>>> 3 Select the stuff between the comma and end of the line (in this
>>>>>> case, it is "So Vast Thou Art").
>>>>>>
>>>>>>
>>>>>> Regards,
>>>>>>
>>>>>> Alan
>>>> --
>>>> Regards,
>>>> Jay Freedman
>>>> Microsoft Word MVP FAQ: http://word.mvps.org
>>>> Email cannot be acknowledged; please post all follow-ups to the
>>>> newsgroup so all may benefit.
>>
>> --
>> Regards,
>> Jay Freedman
>> Microsoft Word MVP FAQ: http://word.mvps.org
>> Email cannot be acknowledged; please post all follow-ups to the newsgroup
>> so all may benefit.


Re: Selecting Specific Range Within A Document Without Search (Word by Alan

Alan
Thu Feb 28 02:48:49 PST 2008

Doug,

Thank you so much. Those worked exactly. I will now look up everything
about them and then apply that to my real-world problem.

By the way, If I wanted to set myrange to continuous section 1 in a
3-section document, how would I do that? I have tried this:
Set myrange = ActiveDocument.Range.Sections(1)

But I get a run-time error 13, type mismatch.

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

Re: Selecting Specific Range Within A Document Without Search (Word 2003) by Doug

Doug
Thu Feb 28 11:25:26 PST 2008

Set myrange = ActiveDocument.Sections(1).Range

--
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" <alanstancliff@nojunkyahoo.com> wrote in message
news:uhzViefeIHA.1824@TK2MSFTNGP02.phx.gbl...
> Doug,
>
> Thank you so much. Those worked exactly. I will now look up everything
> about them and then apply that to my real-world problem.
>
> By the way, If I wanted to set myrange to continuous section 1 in a
> 3-section document, how would I do that? I have tried this:
> Set myrange = ActiveDocument.Range.Sections(1)
>
> But I get a run-time error 13, type mismatch.
>
> 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
>>


Re: Selecting Specific Range Within A Document Without Search (Word by Alan

Alan
Thu Feb 28 12:31:34 PST 2008

Doug Robbins - Word MVP wrote:
> Set myrange = ActiveDocument.Sections(1).Range
>
Thanks, Doug.

I appreciate your help.

Re: Selecting Specific Range Within A Document Without Search (Word by Alan

Alan
Thu Feb 28 13:25:10 PST 2008

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

Re: Selecting Specific Range Within A Document Without Search (Word 2003) by Doug

Doug
Thu Feb 28 14:20:11 PST 2008

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" <alanstancliff@nojunkyahoo.com> 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
>>


Re: Selecting Specific Range Within A Document Without Search (Word by Alan

Alan
Thu Feb 28 18:50:59 PST 2008

Thanks Doug,

I'll be sure to play with that as soon as I get off work.

In the lines that say:
myrange.Start = myrange.start + InStr(myrange, ",")
myrange.End = myrange.Paragraphs(1).Range.End

That includes everything from the comma to the paragraph marker,
including the marker. How would I alter that second line to include
everything up to the paragraph marker but not the paragraph marker itself?

Regards,

Alan Stancliff

Doug Robbins - Word MVP wrote:
> 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
>

Re: Selecting Specific Range Within A Document Without Search (Word 2003) by Doug

Doug
Thu Feb 28 20:10:52 PST 2008

myrange.End = myrange.Paragraphs(1).Range.End - 1

--
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" <alanstancliff@nojunkyahoo.com> wrote in message
news:47C77313.3090707@nojunkyahoo.com...
> Thanks Doug,
>
> I'll be sure to play with that as soon as I get off work.
>
> In the lines that say:
> myrange.Start = myrange.start + InStr(myrange, ",")
> myrange.End = myrange.Paragraphs(1).Range.End
>
> That includes everything from the comma to the paragraph marker, including
> the marker. How would I alter that second line to include everything up to
> the paragraph marker but not the paragraph marker itself?
>
> Regards,
>
> Alan Stancliff
>
> Doug Robbins - Word MVP wrote:
>> 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
>>



Re: Selecting Specific Range Within A Document Without Search (Word by Alan

Alan
Fri Feb 29 00:54:16 PST 2008

Doug Robbins - Word MVP wrote:
> myrange.End = myrange.Paragraphs(1).Range.End - 1
>
Thanks again Doug,

I got a bunch of leads now. And thanks to Tony, Greg, and Jay too (I
hope I didn't forget someone).

Regards,

Alan Stancliff
<