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
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top