I have a small script that brings an open program (Notepad) into focus, and then waits a second before sending the program the function CTRL S
. This script works 50% of the time, while the rest of the time the script makes an error and actually sends a capital S letter right into the .txt file I am editing instead of sending CTRL S
(which is command to save).
Below is the content of the script:
' Create WScript Shell Object to access filesystem.
Set WshShell = WScript.CreateObject("WScript.Shell")
' Select, or bring Focus to a window named `NOTEPAD`
WshShell.AppActivate "Notepad"
WScript.Sleep 1000
WshShell.SendKeys "^s"
Can anyone tell me how this error is occurring? I thought perhaps it was becuase I had CAPSLOCK on, but that was not the case.
Running Windows & 64 bit.
WshShell.AppActivate "Notepad"
in your VBS code and add that same code on the next three lines so you end up with four total lines one right after the other asWshShell.AppActivate "Notepad"
without anysleep
functions in between and then do the 1 second sleep followed by theCtrl+S
. Test to see if this works more than just half the time or all the time, and if so and you'd like, I'll be happy to add an answer.