当我使用另一个密钥而不是"{ENTER}"
时,我会遇到一些麻烦。
"{UP}"
,"{DOWN}"
,"{LEFT}"
和"{RIGHT}"
在cmd.exe
中不起作用,为什么?
Private Sub press_key(key As String)
SendKeys key, True
Application.Wait (Now + TimeValue("0:00:01"))
End Sub
Sub Test()
Call Shell("C:\ ... \name.EXE", vbNormalFocus)
Application.Wait (Now + TimeValue("0:00:01"))
press_key ("{ENTER}")
press_key ("{ENTER}")
press_key ("{DOWN}")
press_key ("{DOWN}")
press_key ("{DOWN}")
press_key ("{RIGHT}")
press_key ("{DOWN}")
press_key ("{DOWN}")
press_key ("{DOWN}")
press_key ("{ENTER}")
End Sub
答案 0 :(得分:1)
您尝试在每个SendKey之间Wait
秒。而不是wait
,而是在SendKeys之间关注应用程序:
Private Sub press_key(key As String)
SendKeys key, True
DoEvents
End Sub
这将改善VBA与应用程序之间的界面。