想請教一個VBA執行ERP的問題,但因為只會使用抓取座標點選按鈕方式執行,所以目前碰到一個問題,就是如何判斷ERP執行畫面是否已跑完,進而可以執行下一步點選下載按鈕。
例如圖一是使用座標點選【O.列印】按鈕後,它會開始執行並顯示「電腦正在作業中,請稍候!」。圖二則是程式已執行完成並顯示下載選項【L.終端機印表】
想確認是否有辦法判斷【L.終端機印表】畫面是否已顯示,如此才能再繼續執行下一段VBA程序。
我目前是使用以下VBA等候時間執行下一段程序,但此作法經常太早或太久才執行導致失敗。
以上求解~~~~~~
Sub 下載ERP()
Dim RetVal
RetVal = Shell("Z:\AutoERP\AutoERP.exe", 3) '開啟ERP
Application.Wait Now + TimeValue("0:01:30") '等候1分30秒
SetCursorPos 220, 160 '移到座標位置
Application.Wait Now + TimeValue("0:00:1")
mouse_event &H2 Or &H4, 0, 0, 0, 0 '點選【L.終端機印表】按鈕
End Sub
你懂用 SetCursorPos 這個 windows API 便很好了,我記得有一個 windows API 是看 cursor 點着顏色的,可以試試
以下參考
http://www.office-cn.net/t/api/index.html?apihelp.htm
https://club.excelhome.net/thread-1141522-1-1.html
網上抄來的,自己研究
#If VBA7 Then
Private Declare PtrSafe Function GetPixel Lib "gdi32" (ByVal hdc As LongPtr, ByVal x As Long, ByVal y As Long) As Long
Private Declare PtrSafe Function GetCursorPos Lib "user32" (ByRef lpPoint As POINT) As LongPtr
Private Declare PtrSafe Function GetWindowDC Lib "user32" (ByVal hwnd As LongPtr) As LongPtr
#Else
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (ByRef lpPoint As POINT) As Long
Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
#End If
Private Type POINT
x As Long
y As Long
End Type
Sub Picture1_Click()
Dim pLocation As POINT
Dim lColour As Long
Dim lDC As Variant
lDC = GetWindowDC(0)
Call GetCursorPos(pLocation)
lColour = GetPixel(lDC, pLocation.x, pLocation.y)
Range("a1").Interior.Color = lColour
End Sub
blanksoul12,超級感謝但果不其然.....我還真看不懂 哈xxxxD
雖然大概知道這是cursor點着顏色效果,但還真不知道怎麼運用到判圖效果上,嗯~~~~這我可能有得學了 哈哈哈哈哈