Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2005

Tip: Looking for answers? Try searching our database.

Selection.Range Unexpectedly Collapses

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Greg Maxey - 08 Oct 2005 16:23 GMT
This came up in a separate topic and I thought it might be lost in the
weeds. I decided to bring it up here in a dedicated post in hope of
stimulating the discussion.

A group of us discovered quite by accident yesterday that if your delete
something that includes the start of a selection.range then the entire
selection is collapsed.  If you delete just part of a selection.range or the
end of a selection.range then the selection is simply resized accordingly.

You can observe this by stepping through the following exercises and
observing the selection:

Sub Experiment1()
Dim oRng1 As Range
Dim oRng2 As Range
Set oRng1 = ActiveDocument.Range
Set oRng2 = ActiveDocument.Range
oRng1.Start = 10
oRng1.End = 20
oRng1.Select
oRng2.Start = 9
oRng2.End = 19
oRng2.Delete 'Selection collapses
End Sub

Sub Experiment2()
Dim oRng1 As Range
Dim oRng2 As Range
Set oRng1 = ActiveDocument.Range
Set oRng2 = ActiveDocument.Range
oRng1.Start = 10
oRng1.End = 20
oRng1.Select
oRng2.Start = 12
oRng2.End = 18
oRng2.Delete 'Selection resizes
End Sub

Sub Experiment3()
Dim oRng1 As Range
Dim oRng2 As Range
Set oRng1 = ActiveDocument.Range
Set oRng2 = ActiveDocument.Range
oRng1.Start = 10
oRng1.End = 20
oRng1.Select
oRng2.Start = 15
oRng2.End = 25
oRng2.Delete 'Selection resizes
End Sub

I am interested in what is happening under the hood in Word that causes the
complete collapse of the selection.range in exercise 1.  Thanks

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

Helmut Weber - 08 Oct 2005 21:25 GMT
Hi Submariner,

the picture of a Word-document, I've made up for me,
is that of a 2-dimensional array,
left to right, like WordCharacter(x, y), where x is the character
and y all kind of information connected with character x.

According to the principle from left to right, it seems,
the crucial part of the information is in the second dimension
of the first character, like:

selection starts here
selection ends there

Still shorter to get the principle:

Selection.Characters.Last.Delete
Selection.Characters.First.Next.Delete
Selection.Characters.First.Delete

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

Greg Maxey - 08 Oct 2005 21:43 GMT
Helmut,

Your experiment like your general code is so much more succinct than mine
;-)

Your explanation certainly sounds plausible.

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> Hi Submariner,
>
[quoted text clipped - 15 lines]
> Selection.Characters.First.Next.Delete
> Selection.Characters.First.Delete
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.