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
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"
Each windows process has an identifier. If you store the process id for each notepad window, you can avoid worrying about finding the right window after its title changes.
Here is an example of opening two notepad files, activating by process id and sending keys.
Set objShell = WScript.CreateObject("WScript.Shell")
Function SendKeysTo (process, keys, wait)
objShell.AppActivate(process.ProcessID)
objShell.SendKeys keys
WScript.Sleep wait
End Function
Set notepadA= objShell.Exec("notepad")
Set notepadB= objShell.Exec("notepad")
WScript.Sleep 500
SendKeysTo notepadA, "Hello I am Notepad A", 1000
SendKeysTo notepadB, "Hello I am Notepad B", 1000
Hopefully you can take a similar approach to solve your problem.