How do I get Excel to tell me the angle of a line
drbob2000 wrote...
I am trying to determine the angle of a line drawn in Excel; I need to acess
angles from digital photos...so I import the photo and draw a line on it....I
need to know the angle of the line.
A single line on it's own has no angles, or at any point has two rays
that form a 180 degree angle. Do you mean relative to the horizontal?
If so, drawn lines have Height and Width properties relative to their
'top-left' endpoint. Pass them as arguments to the worksheet function
ATAN2 to get the angle in radians.
As an example, run this macro after selecting a drawn line.
Sub rfh()
Dim s As Shape
If TypeOf Selection Is Line Then
Set s = ActiveSheet.Shapes(Selection.Index)
Else
Exit Sub
End If
With Application.WorksheetFunction
MsgBox _
prompt:=.Atan2(s.Width, IIf(s.VerticalFlip, 1, -1) *
s.Height), _
Title:="Angle selected line forms to the horizontal (in
radians)"
End With
End Sub
|