VBA Excel Sendkeys ARROW在cmd.exe中不起作用

时间:2016-05-25 13:47:46

标签: excel vba excel-vba cmd

当我使用另一个密钥而不是"{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

Excel launch the console

1 个答案:

答案 0 :(得分:1)

您尝试在每个SendKey之间Wait秒。而不是wait,而是在SendKeys之间关注应用程序:

Private Sub press_key(key As String)
    SendKeys key, True
    DoEvents
End Sub

这将改善VBA与应用程序之间的界面。