Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Type POINTAPI
X As Long
Y As Long
End Type
Public Function getmouse_x_y() As POINTAPI
GetCursorPos getmouse_x_y
End Function
sub test()
'call getmouse_x_y '调用“获取鼠标坐标值过程”(假定你们给的过程/程序,名叫getmouse_x_y)
if getmouse_x_y.x>100 and getmouse_x_y.y>100 then …… '根据返回当前鼠标的坐标值执行某过程/程序
……
end sub
只有在窗体中才有鼠标移动事件
在VBA中添加一个窗体,双击窗体输入代码:
Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Range("c1") = X
Range("c2") = Y
End Sub
运行时,只要鼠标在窗体上移动,就能在C1与C2单元格中显示坐标。
你想干什么,你可以用worksheet的selectionchang事件或chang事件来解决呀 ,你是不是想取得选定单元格的行号和列标呀
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Print X, Y
End Sub
主要是写在鼠标的移动事件里mousemove
可以用ontime解决这个问题,隔几分钟获取一次,前后比对不就可以了