Hi,
Using the following code I've found on the net today I'm capturing coordinates of mouse clicks (2) and then trying to plot a line (arrow) from the first click to the second. It basically works but the arrow isn't matching being placed where I clicked. The near I am to the top left-hand side of the screen the more accurate the plotted line is.
I'm guessing it may have something to do with twips and zoom but unfortunately the answer is beyond my capabilities.
Sub CaptureClicks()
Dim MousePT As POINTAPI
Dim x As Double, y As Double
GetCursorPos MousePT
x = MousePT.x
y = MousePT.y
If [T1] <> "" And [T2] <> "" Then
[T1] = ""
[T2] = ""
[U1] = ""
[U2] = ""
End If
If [T1].Value = 0 Then
[S1] = "Click 1"
[T2] = ""
[U2] = ""
[T1] = x
[U1] = y
Else
[S2] = "Click 2"
[T2] = x
[U2] = y
End If
xLoc1 = [T1].Value
xLoc2 = [T2].Value
yLoc1 = [U1].Value
yLoc2 = [U2].Value
If [T2] <> 0 Then
Set myShape = ActiveSheet.Shapes.AddLine(xLoc1, yLoc1, xLoc2, yLoc2)
With myShape
.Name = "ArrowSegment" & CStr(Ipts)
With .Line
.ForeColor.SchemeColor = 12 ' blue
.EndArrowheadLength = msoArrowheadLong
.EndArrowheadWidth = msoArrowheadWidthMedium
.EndArrowheadStyle = msoArrowheadTriangle
End With
End With
End If
End Sub
Andrew
Using the following code I've found on the net today I'm capturing coordinates of mouse clicks (2) and then trying to plot a line (arrow) from the first click to the second. It basically works but the arrow isn't matching being placed where I clicked. The near I am to the top left-hand side of the screen the more accurate the plotted line is.
I'm guessing it may have something to do with twips and zoom but unfortunately the answer is beyond my capabilities.
Sub CaptureClicks()
Dim MousePT As POINTAPI
Dim x As Double, y As Double
GetCursorPos MousePT
x = MousePT.x
y = MousePT.y
If [T1] <> "" And [T2] <> "" Then
[T1] = ""
[T2] = ""
[U1] = ""
[U2] = ""
End If
If [T1].Value = 0 Then
[S1] = "Click 1"
[T2] = ""
[U2] = ""
[T1] = x
[U1] = y
Else
[S2] = "Click 2"
[T2] = x
[U2] = y
End If
xLoc1 = [T1].Value
xLoc2 = [T2].Value
yLoc1 = [U1].Value
yLoc2 = [U2].Value
If [T2] <> 0 Then
Set myShape = ActiveSheet.Shapes.AddLine(xLoc1, yLoc1, xLoc2, yLoc2)
With myShape
.Name = "ArrowSegment" & CStr(Ipts)
With .Line
.ForeColor.SchemeColor = 12 ' blue
.EndArrowheadLength = msoArrowheadLong
.EndArrowheadWidth = msoArrowheadWidthMedium
.EndArrowheadStyle = msoArrowheadTriangle
End With
End With
End If
End Sub
Andrew