Rod
Rod

Reputation: 752

VBA Excel Sendkeys ARROW don't work in cmd.exe

i have some troubles when i will use another key than "{ENTER}".

"{UP}", "{DOWN}", "{LEFT}" and "{RIGHT}" don't work in cmd.exe, why ?

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

Upvotes: 1

Views: 510

Answers (1)

Gary's Student
Gary's Student

Reputation: 96771

You are trying to Wait one second between each SendKey. Rather than waiting, give focus to the app between SendKeys:

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

This will improve the interface between VBA and the app.

Upvotes: 2

Related Questions