2017-02-09 202 views
0

我要的SendKeys到記事本Application.Wait和使用AppActivate不會的SendKeys

有個記事本中正常工作已經打開的代碼如下

AppActivate "Blocco Note" 
Application.Wait Now + TimeValue("00:00:02") 
Call SendKeys("sdfse", True) 
.... 
Call SendKeys("sdfse", True) 

我即使Applicatio.OnTime

嘗試
Sub test1 
    AppActivate "Blocco Note" 
    Application.OnTime Now + TimeValue("00:00:02"), "test2" 
End Sub 

Sub test2() 
    Call SendKeys("sdfse", True) 
    .... 
    Call SendKeys("sdfse", True) 
end Sub 

問題是,它等待2秒,然後才激活記事本,所以第一個sendkeys不起作用

你可以請求幫忙嗎?

非常感謝你

編輯:我做了一些測試,我發現代碼工作僅在磨片記事本沒有最小化。

+1

爲什麼不直接寫txt文件呢? SendKeys到記事本看起來像史詩般的比例矯枉過正。 – Comintern

+0

這只是一個測試..我需要理解爲什麼application.ait不能正常工作 –

+1

在AppActivate後面放入一個DoEvents調用,讓Excel處理消息泵。 – Comintern

回答