I am new to VB Scripting. I want the VB script to act according to an event of an application. Eg : The VBScript should wait till a popup message appears in an application.
问题:
回答1:
VBScript and Windows Script Host only support primitive GUI automation, like activating windows (the AppActivate
method) and sending keystrokes (the SendKeys
methods). So I doubt that your task can be accomplished with pure VBScript.
However, there's a free GUI automation tool called AutoIt that should be able to do what you need.
回答2:
If all you want is to close a pop-up, this may help you:
Set oShell = CreateObject("WScript.Shell")
Do
bResult = oShell.AppActivate("Title of the dialog box")
If bResult = True Then
oShell.SendKeys "%N" ' Alt+N, you may send {Esc} or {Enter} if you want
Exit Do
End If
WScript.Sleep 500
Loop
回答3:
Depending on the application, the object model can be used to automate most functions. I routinely automate Excel using the Excel Object Model. Here is a link to the documentation at MSDN:
http://msdn.microsoft.com/en-us/library/aa209782%28office.10%29.aspx
I usually turn off the pop-up menus when possible to prevent them from causing unexpected events for the script to handle. Here is an example:
'Create an new instance of Excel to work with
Set objExcel = CreateObject("Excel.Application")
Set objBook = objExcel.Workbooks.Open("C:\Test.xls")
Set objSheet = objStartsBook.Sheets(1)
'Make Excel visible on the screen for the user
objExcel.Visible = True
'Turn off pop up dialog boxes from excel so the script can control the app
objExcel.DisplayAlerts = False
From here, I would continue to used the object model for Excel to get the application to do whatever task I need.
The trick is thinking about what members and methods are needed to accomplish the task you want versus how a person interacts with the GUI.