マウスカーソルの座標を取得する。
VBAでマウスカーソルの座標位置を取得するにはGetCursorPos関数を利用して取得します。
X軸、Y軸の座標位置は構造体内の変数を使用して取得します。
●座標の取得
#If VBA7 And Win64 Then
Declare PtrSafe Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Declare PtrSafe Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
#Else
Declare Function GetCursorPos Lib "user32" (lpPoint As Point) As Long
Declare PtrSafe Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
#End If
Type Point
X As Long
Y As Long
End Type
'******************************************************************
' カーソル座標取得
'******************************************************************
Sub getMousePoint()
Dim pCursol As Point
GetCursorPos pCursol
'座標の取得
Debug.Print "X軸 : " & pCursol.X
Debug.Print "Y軸 : " & pCursol.Y
End Sub■実行結果



