Board logo

標題: 以下指令是什麼意思 [打印本頁]

作者: cdkee    時間: 2010-11-4 17:35     標題: 以下指令是什麼意思

請教大大,以下VBA,每行指令是什麼意思,謝謝!

'**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:
XLMAIN是EXCEL的"系統名稱" FINDWINDOW 用來找出EXCEL的"ID:  (即HANDLE)
用來作日後指定版面做操作,如TEST下的SETCURSORPOS

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



    謝謝版大詳細說明!理解中...




歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)