'**Win32 API Declarations
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal IpClassName As String, ByVal IpWindowName As String) As Long
Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, IpRect As RECT) As Long
'**Win32 API User Defined Types
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Sub test()
Dim Rec As RECT
'Get Left, Right, Top and Bottom of Form1
GetWindowRect GetWindowHandle, Rec
'Set Cursor position on X
SetCursorPos Rec.Right - 600, Rec.Top + 400
End Sub
Private Function GetWindowHandle() As Long
Const CLASSNAME_M**cel="XLMAIN"
'Gets the Apps window handle, since you can't use App.hInstance in VBA (VB Only)
GetWindowHandle = FindWindow(CLASSNAME_M**cel, vbNullString)
End Function作者: kimbal 時間: 2010-11-5 00:06
SUB TEST以上的是API定義,用來呼叫WINDOW系統的"小程序"
這裡有3個"小程序":FindWindow,SetCursorPos,GetWindowRect
Private Sub test()
Dim Rec As RECT 這句你可以當是存坐標的變量REC
GetWindowRect GetWindowHandle, Rec 把EXCEL的坐標放到REC
SetCursorPos Rec.Right - 600, Rec.Top + 400 把老鼠放到EXCEL右上角向左600點位和上方對下400點位
End Sub
GetWindowHandle可寫成
Private Function GetWindowHandle() As Long
GetWindowHandle = FindWindow("XLMAIN", vbNullString)
End Function作者: cdkee 時間: 2010-11-5 02:19
SUB TEST以上的是API定義,用來呼叫WINDOW系統的"小程序"
這裡有3個"小程序":FindWindow,SetCursorPos,GetW ...
kimbal 發表於 2010-11-5 00:06