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 / August 2005

Tip: Looking for answers? Try searching our database.

Check if or where two ranges intersect?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ed - 02 Aug 2005 18:21 GMT
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
Jean-Guy Marcil - 02 Aug 2005 19:36 GMT
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

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

 
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.