Try this
Option Explicit
'based on
'ref http://www.devx.com/tips/Tip/33124
Const cPI As Double = 3.14159265358979
Function getAngleBetweenLinesVect(commonX As Double, commonY As Double, _
X1 As Double, Y1 As Double, _
Y2 As Double, X2 As Double) As Double
Dim aRadians As Double
Dim diffX1 As Double, diffX2 As Double, diffY1 As Double, diffY2 As Double
'check if both the lines are the same, if they are exit the function
If (commonY = Y1 And commonX = X1) Or _
(commonY = Y2 And commonX = X2) Or _
(Y1 = Y2 And X1 = X2) Then
getAngleBetweenLinesVect = 0#
Exit Function
End If
'set the variables
diffX1 = commonX - X1
diffY1 = commonY - Y1
diffX2 = commonX - X2
diffY2 = commonY - Y2
'applying the angle between two lines vector rule, calculate the angle in radians
aRadians = invCos(((diffX1 * diffX2) + (diffY1 * diffY2)) / _
(Sqr(diffX1 ^ 2 + diffY1 ^ 2) * Sqr(diffX2 ^ 2 + diffY2 ^ 2)))
'convert to degrees
getAngleBetweenLinesVect = aRadians * 180# / cPI
End Function
'the inverse cos function. Returns an angle.
Public Function invCos(X As Double) As Double
If X > 1 Or X < -1 Then
'if the ratio supplies is outside the acceptable range.
ElseIf X = 1 Then
invCos = 0
ElseIf X = -1 Then
invCos = cPI
Else
invCos = (Atn(-X / Sqr(-X * X + 1)) + 2 * Atn(1))
End If
End Function