3

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.

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

Comments

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 

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.