Reputation: 25
My Windows VBScript opens an InternetExplorer.Application object, and runs through some navigation. At one point the page I'm working with displays a dialog box in which I must click "OK" or "Cancel." Is there a way to tell the VBScript to click "OK" when the dialog box pops up?
Upvotes: 0
Views: 4376
Reputation: 226
If all you want is to close a dialog box, this may help you:
Set oShell = CreateObject("WScript.Shell")
Do
bResult = oShell.AppActivate("Title of the dialog box")
If bResult = True Then
oShell.SendKeys "{Enter}"
' or "%K" for Alt+k, for OK and "%N" (Alt+N) for Cancel
Exit Do
End If
WScript.Sleep 500
Loop
Upvotes: 1
Reputation: 670
VBScript isn't very good at dealing with GUI functions, at least, it is not even remotely close to something like AutoIT; anyway, that said there is a sendkeys function in VBScript, but the problem is that you can't do an "on event" type of call, you basically have to use a timer, so it really isn't a good solution, but as far as I know it's all you've got, at least natively to VBS.
So maybe you could kick off your IE object, then throw in a wait timer and then sendkeys. WAY hokey... but it could work.
Here's the MSDN article on sendkeys with examples.
Upvotes: 1