2013-11-21 78 views
0

我想創建一個VBA腳本,將打開一個膩子窗口,輸入用戶信息(用戶名,密碼等),向下鍵(向下箭頭)到正確的菜單選項,然後打開該菜單選項。VBA Keydown問題

該腳本工作正常,但我不能讓keydown函數與膩子正常工作。腳本是否放在窗口上?我錯誤地使用keydown函數?有沒有更好的方法來寫這個動作?

Sub Putty() 
    ' 
    Dim puttyID As String 

    puttyID = Shell("C:\Program Files (x86)\PuTTY\putty.exe", vbNormalFocus) 

    newHour = Hour(Now()) 
    newMinute = Minute(Now()) 
    newSecond = Second(Now()) + 3 
    waitTime = TimeSerial(newHour, newMinute, newSecond) 
    Application.Wait waitTime 

    SendKeys "information", True 
    SendKeys "{ENTER}, True" 

    newHour = Hour(Now()) 
    newMinute = Minute(Now()) 
    newSecond = Second(Now()) + 3 
    waitTime = TimeSerial(newHour, newMinute, newSecond) 
    Application.Wait waitTime 

    SendKeys "user", True 
    SendKeys "~", True 

    newHour = Hour(Now()) 
    newMinute = Minute(Now()) 
    newSecond = Second(Now()) + 1 
    waitTime = TimeSerial(newHour, newMinute, newSecond) 
    Application.Wait waitTime 

    SendKeys "password", True 
    SendKeys "~", True 

    newHour = Hour(Now()) 
    newMinute = Minute(Now()) 
    newSecond = Second(Now()) + 2 
    waitTime = TimeSerial(newHour, newMinute, newSecond) 
    Application.Wait waitTime 

    SendKeys "ID", True 
    SendKeys "~", True 
    SendKeys "~", True 

    newHour = Hour(Now()) 
    newMinute = Minute(Now()) 
    newSecond = Second(Now()) + 2 
    waitTime = TimeSerial(newHour, newMinute, newSecond) 
    Application.Wait waitTime 

    SendKeys "2", True 

    newHour = Hour(Now()) 
    newMinute = Minute(Now()) 
    newSecond = Second(Now()) + 1 
    waitTime = TimeSerial(newHour, newMinute, newSecond) 
    Application.Wait waitTime 

    SendKeys "{Down}", True 
    SendKeys "{Down}", True 
    SendKeys "~", True 

末次

回答

0

的應用程序可能無法獲得足夠的時間來應對的SendKeys。我建議把一個:

的DoEvents

聲明立即那似乎越來越忽視任何SendKeys語句如下。