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 / Excel / Programming / January 2007

Tip: Looking for answers? Try searching our database.

Line Start and End Coordinates

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Zone - 25 Jan 2007 20:27 GMT
I have a line on the screen (shape).  I would like to select it and get the
starting and ending  coordinates of the line.  TIA, James
Kari J Keinonen - 25 Jan 2007 21:31 GMT
Hi!

> I have a line on the screen (shape).  I would like to select it and get the
> starting and ending  coordinates of the line.  TIA, James

I hope that next code help you a little.

   ActiveSheet.Shapes(1).Select                  'if you have only one line
   Range("A1").Value = Selection.ShapeRange.Item(1).Left
   Range("A2").Value = Selection.ShapeRange.Item(1).Width
   Range("A3").Value = Selection.ShapeRange.Item(1).Top
   Range("A4").Value = Selection.ShapeRange.Item(1).Height

Regards,
Kari J Keinonen
Peter T - 25 Jan 2007 21:47 GMT
The "flips" help work out which pair of corners of the imaginary rectangle,
that surround the line, represent the correct diagonal. (I tried to make
that short!)

Sub test()
Dim bHflip As Boolean, bVflip As Boolean
Dim nBegin As Long, nEnd As Long
Dim shp As Shape
Dim aC(1 To 4, 1 To 2) As Double

Set shp = ActiveSheet.Shapes("Line 1")
With shp
   aC(1, 1) = .Left: aC(1, 2) = .Top
   aC(2, 1) = .Left + .Width: aC(2, 2) = .Top
   aC(3, 1) = .Left: aC(3, 2) = .Top + .Height
   aC(4, 1) = .Left + .Width: aC(4, 2) = .Top + .Height

   bHflip = .HorizontalFlip
   bVflip = .VerticalFlip
End With

If bHflip = bVflip Then
   If bVflip = False Then
       ' down to right
       nBegin = 1: nEnd = 4
   Else
       ' up to left
       nBegin = 4: nEnd = 1
   End If
ElseIf bHflip = False Then
   ' up to right
   nBegin = 3: nEnd = 2
Else
   ' down to left
   nBegin = 2: nEnd = 3
End If

Debug.Print "Begin X:Y", "End X:Y"
Debug.Print aC(nBegin, 1); aC(nBegin, 2), aC(nEnd, 1); aC(nEnd, 2)

End Sub

Regards,
Peter T

> I have a line on the screen (shape).  I would like to select it and get the
> starting and ending  coordinates of the line.  TIA, James
Zone - 26 Jan 2007 12:02 GMT
Thanks very much, Peter and Kari.  Your replies are very helpful to me.
James

> The "flips" help work out which pair of corners of the imaginary
> rectangle,
[quoted text clipped - 45 lines]
> the
>> starting and ending  coordinates of the line.  TIA, James
 
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.