I have a simple script that hunts for popup boxes that are generated for website and Excel. It works most of the time but errors out occasionlly and seemingly randomly. The error is line: 6 Char: 3 Error: Invalid window handle Code: 80070578
I can't figuer out why it'll work for hours then error seemingly at random. Also the script uses a lot of CPU if anyone could advise how to make it more efficent. Thanks For your time
Set WshShell = CreateObject("WScript.Shell")
Do
Do
ret = WshShell.AppActivate("Message from webpage")
ret2 = WshShell.AppActivate("Microsoft Excel")
Loop Until ret = True or ret2 = True
WScript.sleep 500
ret = WshShell.AppActivate("Message from webpage")
ret2 = WshShell.AppActivate("Microsoft Excel")
If ret = True or ret2 = True Then
WScript.Sleep 200
WshShell.SendKeys("{ENTER}")
End If
WScript.sleep 500
Loop