沒辦法通過COM,你可以通過Winapi的方式發送消息的功能。像下面的東西可以工作,雖然它非常笨重。我在一些自動化項目中使用它來模擬點擊註釋按鈕。
Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function GetWindow Lib "user32" Alias "GetWindow" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
' GetWindow() Constants
Public Const GW_HWNDFIRST = 0
Public Const GW_HWNDLAST = 1
Public Const GW_HWNDNEXT = 2
Public Const GW_HWNDPREV = 3
Public Const GW_OWNER = 4
Public Const GW_CHILD = 5
Public Const GW_MAX = 5
'button click constants for SendMessage
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_LBUTTONUP = &H202
Public Const BM_SETSTATE = &HF3
Public Const BM_GETSTATE = &HF2
Public Const BM_CLICK = &HF5
Public hwndAction As String
Public hwndClass As String
Public hwndCaption As String
Public hwndHandle As Long
Sub ClickNotes()
hwndAction = "FindHandle"
hwndCaption = "WindowCaption" ''Window Caption here
hwndClass = "NotesSubprog"
FindChildWindows(FindWindow("SWT_Window0", "Windowtitle"))
hwndAction = "FindHandle"
hwndCaption = "WindowCaption"
hwndClass = "NotesSubprog"
FindChildWindows(hwndHandle)
hwndAction = "FindHandle"
hwndCaption = ""
hwndClass = "ActionBar"
FindChildWindows(hwndHandle)
hwndAction = "Click"
hwndCaption = "Comment"
hwndClass = "IRIS.bmpbutton"
FindChildWindows(hwndHandle)
Do While FindWindow("SWT_Window0","New Comment - IBM Notes") = 0
DoEvents
Loop
Wait 3
End Sub
'the method signature is like this only to stay compatible with the Win32 API - lParam will not be used anyway
Function EnumChildWindow(ByVal hChild As Long, ByVal lParam As Long) As Long
Dim ClassBuffer As String
Dim CaptionBuffer As String
Dim TempVar As Long
ClassBuffer = Space(150)
TempVar = GetClassName(hChild, ClassBuffer, 149)
ClassBuffer = Left(ClassBuffer, TempVar)
CaptionBuffer = Space(250)
TempVar = GetWindowText(hChild, CaptionBuffer, 250)
CaptionBuffer = Left(CaptionBuffer, TempVar)
Debug.Print "Handle: " & hChild & ", Class: " & ClassBuffer & ", Caption: " & CaptionBuffer
If hwndClass = ClassBuffer And hwndCaption = CaptionBuffer Then
Select Case hwndAction
Case "Click"
SendMessage(hChild, WM_LBUTTONDOWN, 0, 0)
SendMessage(hChild, WM_LBUTTONUP, 0, 0)
SendMessage(hChild, BM_SETSTATE, 1, 0)
Case "FindHandle"
hwndHandle = hChild
End Select
Exit Function
End If
'Continue enumeration by recursion
EnumChildWindow = True
End Function
Function FindChildWindows(ByVal hParent As Long)
Dim hChild As Long
Dim Continue As Boolean
Continue = True
hChild = GetWindow(hParent, GW_CHILD)
Continue = EnumChildWindow(hParent, 0)
While Not hChild = 0 And Continue
If Continue Then Continue = FindChildWindows(hChild)
hChild = GetWindow(hChild, GW_HWNDNEXT)
Wend
FindChildWindows = Continue
End Function
你究竟想要做什麼? '我需要完成所有流程'是什麼意思? 如果您試圖使用VBA模仿Notes應用程序中的代碼,您需要有人與您共享該代碼,以便您可以在VBA中重寫該代碼,或者您將不得不通過試用反向設計代碼,錯誤。不知道「過程」是什麼,很難提供任何好的幫助。 – user1918954