Send keys issues with VBA

Radoslaw Poprawski

Active Member
Joined
Jun 19, 2021
Messages
398
Office Version
  1. 365
Platform
  1. Windows
Hi.
I have the following code:
VBA Code:
Sub Cisco_start()

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run """%PROGRAMFILES(x86)%\Cisco\Cisco AnyConnect Secure Mobility Client\vpnui.exe"""

WshShell.AppActivate "Cisco AnyConnect Secure Mobility Client"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{ENTER}"

End Sub

and I can start the program, however all the "send keys" command do is implement TABB or ENTER within VBA editor and it does not pass it to cisco app.

any help?
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Try giving the cisco program some time to load.

VBA Code:
Sub Cisco_start()

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run """%PROGRAMFILES(x86)%\Cisco\Cisco AnyConnect Secure Mobility Client\vpnui.exe"""

Application.Wait (Now + TimeValue("0:00:03"))

WshShell.AppActivate "Cisco AnyConnect Secure Mobility Client"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{ENTER}"

End Sub
 
Upvote 0
Thank you,
but it does not help
the "TAB" key is still being send str8 into VBA editor changing the code from:
VBA Code:
Sub Cisco_start()

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run """%PROGRAMFILES(x86)%\Cisco\Cisco AnyConnect Secure Mobility Client\vpnui.exe"""

Application.Wait (Now + TimeValue("0:00:03"))

WshShell.AppActivate "Cisco AnyConnect Secure Mobility Client"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{ENTER}"

End Sub
To:

VBA Code:
Sub Cisco_start()

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run """%PROGRAMFILES(x86)%\Cisco\Cisco AnyConnect Secure Mobility Client\vpnui.exe"""

Application.Wait (Now + TimeValue("0:00:03"))

WshShell.AppActivate "Cisco AnyConnect Secure Mobility Client"
WshShell.SendKeys "{TAB}"
    WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{ENTER}"

End Sub

and if i go thru other steps it does the same - just adding keys to the vba editor.
 
Upvote 0
It's going to do that if you run the macro from the VBE. You need to launch it from a button and the cisco program must have focus. Get it working with NotePad.exe first, then move to the Cisco app.
Also, why are you using Set WshShell = CreateObject("WScript.Shell")?

VBA has a built in shell command along with Excel's built in Application.Sendkeys command.
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,250
Members
452,623
Latest member
Techenthusiast

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top