最近在使用 ui automationcore.dll 在VBA中制作一些簡單的自動化,
查找 listview / treeview / saveas dialog 等控制元件視窗,點擊上面的按鈕,
遇到了兩個問題,感覺在 vba中呼叫 UI automation 好像并不是很穩定。
代碼一.
Set oSearchUIElement = oUIElement.FindFirst(vTreeScope, oFinalCondition),
有的時候這一句并不能直接生效,oSearchUIElement 依然是nothing,如果不加判斷向下運行,就會出現 automation error等 錯誤提示.
有沒有更好的辦法來避免這種情況?
While oSearchUIElement Is Nothing
Set oSearchUIElement = oUIElement.FindFirst(vTreeScope, oFinalCondition)
If oSearchUIElement Is Nothing Then
Sleep (100)
End If
Wend
代碼一二。
使用點擊按鈕的方法 - invoke之后,有的時候被模擬的那個系統會處于未回應狀態,然后下面的這一句InvokePat.Invoke也就卡住了,不往下運行了,每次都需要等大約2-3秒之后之后,代碼才能繼續,有的時候等待回應的時間會更長,而且經常會在invoke之后會報錯,我只能在invoke之前加上on error resume next 才能繼續。
Obj.SetFocus
Set InvokePat = oElement2ActOn.GetCurrentPattern(UIA_InvokePatternId)
InvokePat.Invoke
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/38722.html
標籤:API
