I'm am trying to send some keystrokes to a program. I have some example code below which works fine up until the final {Alt}
command. I believe this is due to the window name changing from "Notepad1"
to "NotePad2"
. Could anyone help me change the AppActivate
path to "Notepad2"
after the objShell.SendKeys "{Enter}"
command?
Example:
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "Notepad.exe"
Do Until Success = True
Success = objShell.AppActivate("NotepadPathA")
Loop
objShell.SendKeys "{F1}"
objShell.SendKeys "Secure06**"
objShell.SendKeys "{Enter}"
Shell.SendKeys "{Alt}"
Shell
on your last line but you haven't defined it. Change it to objShell
instead.To send the Alt
key, use "%"
. For example:
objShell.SendKeys "%"
You would typically use this in a key combination. For example, to open the File
menu in most programs, you would use Alt
+F
, or:
objShell.SendKeys "%f"
If your window title changes, or you need to activate a new window for whatever reason, just call AppActivate
again:
objShell.AppActivate "My new window title"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With