L
Larry
This is a really basic and maybe foolish-sounding question about the
syntax of ranges, but it's
something that's never made sense to me so I might as well ask.
Here is sample code that selects from the first through the fifth
character of the current paragraph:
Dim r As Range
Set r = Selection.Range
ActiveDocument.Range(r.Paragraphs(1).Range.Start,
r.Paragraphs(1).Range.Characters(5).End).Select
"ActiveDocument.Range" is the range
that equals the entire document. The range start and end information
inside
the parentheses defines a specific range that runs from the start of the
current paragraph to the end of the fifth character in the current
document. My question is, how does VBA derive from one to the other?
If
ActiveDocument.Range is the range of the whole document, then that's
what it is, isn't it? It seems to me that "ActiveDocument.Range" is
saying one thing, and "(r.Paragraphs(1).Range.Start,
r.Paragraphs(1).Range.Characters(5).End)" is saying another. My point
is, why is "ActiveDocument.Range" necessary at all? What purpose
syntactically does it serve in the code?
Is the idea that any range has to begin with the whole document, and
then its beginning and end is marked out within the document?
This seems to be the case, since I try to do the same thing by starting
like this:
Selection.Paragraphs(1).Range(
When I type the open paren I don't get the prompt to type in the start
of the range. And this is the case, even though
Selection.Paragraphs(1).Range is as much a range as ActiveDocument.Range
is. Yet only the latter will work for having a parenthetical statements
containing the start and end of the range.
Maybe my question could be answered if the VBA code were translated into
descriptive language.
I think I've been partly handicapped in my use of ranges because the
syntax itself has never made complete sense to me.
Thanks for any clarification,
Larry
syntax of ranges, but it's
something that's never made sense to me so I might as well ask.
Here is sample code that selects from the first through the fifth
character of the current paragraph:
Dim r As Range
Set r = Selection.Range
ActiveDocument.Range(r.Paragraphs(1).Range.Start,
r.Paragraphs(1).Range.Characters(5).End).Select
"ActiveDocument.Range" is the range
that equals the entire document. The range start and end information
inside
the parentheses defines a specific range that runs from the start of the
current paragraph to the end of the fifth character in the current
document. My question is, how does VBA derive from one to the other?
If
ActiveDocument.Range is the range of the whole document, then that's
what it is, isn't it? It seems to me that "ActiveDocument.Range" is
saying one thing, and "(r.Paragraphs(1).Range.Start,
r.Paragraphs(1).Range.Characters(5).End)" is saying another. My point
is, why is "ActiveDocument.Range" necessary at all? What purpose
syntactically does it serve in the code?
Is the idea that any range has to begin with the whole document, and
then its beginning and end is marked out within the document?
This seems to be the case, since I try to do the same thing by starting
like this:
Selection.Paragraphs(1).Range(
When I type the open paren I don't get the prompt to type in the start
of the range. And this is the case, even though
Selection.Paragraphs(1).Range is as much a range as ActiveDocument.Range
is. Yet only the latter will work for having a parenthetical statements
containing the start and end of the range.
Maybe my question could be answered if the VBA code were translated into
descriptive language.
I think I've been partly handicapped in my use of ranges because the
syntax itself has never made complete sense to me.
Thanks for any clarification,
Larry