Check if or where two ranges intersect?

E

Ed

Is it possible in Word 2000 to find if two ranges intersect, and if so
where? For instance, I have a section of my document as a range, and I want
to find out if an inserted text block with its own range definition is
contained within that section's range. Is it possible?

Ed
 
J

Jean-Guy Marcil

Ed was telling us:
Ed nous racontait que :
Is it possible in Word 2000 to find if two ranges intersect, and if so
where? For instance, I have a section of my document as a range, and
I want to find out if an inserted text block with its own range
definition is contained within that section's range. Is it possible?

Try this:

Dim secRge As Range
Dim textRge As Range

Set secRge = ActiveDocument.Sections(2).Range
Set textRge = Selection.Range

If textRge.InRange(secRge) Then
MsgBox "The selected range is contained in the target section."
ElseIf (textRge.Start > secRge.Start And textRge.Start < secRge.End) Or _
(textRge.End < secRge.End And textRge.End > secRge.Start) Then
MsgBox "The two ranges intersect."
Else
MsgBox "The two ranges are distinct."
End If


--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
[email protected]
Word MVP site: http://www.word.mvps.org
 
Top