In addition to Helmut's excellent examples, I think a bit of learning
about theory is necessary....
The help topics don't always make it clear what they're talking about,
but there are two possible meanings for the word 'Range' in those
discussions.
- An object within a document may have a .Range property, for example
ActiveDocument.Sections(1).Range. Think of this as the 'size' of that
object, like the width of your house. It won't change unless you edit
the text in the section. You can't collapse it. I would think that
trying to run the .Collapse method of this kind of range should
generate an error, but VBA wasn't written to do that.
- A user-declared Range object is something else. Think of it like a
tape measure that you could stretch out to measure the width of your
house -- it isn't actually attached to the house, and you can roll it
up or move it around. You _can_ do this:
Dim myRange As Range
Set myRange = ActiveDocument.Sections(1).Range
myRange.Collapse Direction:=wdCollapseEnd
The Set statement is like measuring the section, making the Start of
myRange equal the Start of the section's range and making the End of
myRange equal the End of the section's range. Then the Collapse
changes the Start of myRange to be the same as the End of myRange. You
haven't changed the section's range at all; you just "rolled up the
tape measure" to the end of the section (actually, as Helmut pointed
out, the start of the next section if there is one). Then you can use
myRange.Select to move the Selection there.
The Selection behaves like a user-declared Range object, except that
the actual selected area in the document moves with it. That's why you
can do Selection.Collapse.
>Hi M,
>
[quoted text clipped - 48 lines]
>
>Vista Small Business, Office XP
--
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.
Tony Jollans - 18 Dec 2007 15:19 GMT
If I may, I'll add my two penn'orth here as you can actually collapse a
Section Range and it does have an effect. It's just that the effect is often
hidden by later actions.
A Range *Object* - any range - is like Jay's tape measure. Every time you
set a range object, you unroll your measure. For a user-defined Range this
is when you use a Set statement. For a system-defined Range object it is
when you use the Range *Property* on the parent object.
This effect is more oftem seen - and taken advantage of, perhaps
unwittingly, - when using Find and Replace, but ...
You *can* do this to achieve the original aim:
With ActiveDocument.Sections(Selection.Sections(1).Index).Range
.Collapse wdCollapseEnd
.Select
End With
But you can *not* use this to do it:
ActiveDocument.Sections(Selection.Sections(1).Index).Range.Collapse
wdCollapseEnd
ActiveDocument.Sections(Selection.Sections(1).Index).Range.Select
... because using the Range Property to get the Range Object in the second
statement rolls out the tape measure anew.

Signature
Enjoy,
Tony
> In addition to Helmut's excellent examples, I think a bit of learning
> about theory is necessary....
[quoted text clipped - 91 lines]
> Email cannot be acknowledged; please post all follow-ups to the newsgroup
> so all may benefit.
mirin - 19 Dec 2007 01:59 GMT
Helmut, Jay, Greg, Tony
Wow! Thank you so much for taking out the time to explain things so
clearly.
I now understand how to use the Collapse method correctly and the
different ways in which I can achieve my original aim of moving the
insertion point to the end of a section.
Now I'll have to sit down and meditate on what the Gurus have
taught :)
Thank You!!
M
On Dec 19, 12:19 am, "Tony Jollans" <My forename at my surname dot
com> wrote:
> If I may, I'll add my two penn'orth here as you can actually collapse a
> Section Range and it does have an effect. It's just that the effect is often
[quoted text clipped - 123 lines]
> > Email cannot be acknowledged; please post all follow-ups to the newsgroup
> > so all may benefit.