Advanced Windows PowerShell Scripting Video Training

Advanced Windows PowerShell Scripting Video Training
Advanced Windows PowerShell Scripting Video Training

Wednesday, July 15, 2009

When do you use ConnectObject in VBScript?

`The WScript.ConnectObject allows you to receive events from an application and have your script act on it. The following code came from DevGuru at http://www.devguru.com/Technologies/wsh/quickref/wscript_ConnectObject.html.

Code:
Set objWord = WScript.CreateObject("Word.Application")WScript.ConnectObject objWord, "objWord_"

objWord.visible = True
blnWordVisible = True

Do While blnWordVisible
WScript.Sleep 500
Loop

Sub objWord_Quit
blnWordVisible = False
WScript.Echo "You quit Word."
End Sub

Sub objWord_DocumentChange
WScript.Echo "You switched documents."
End Sub

Output:
You switched documents.
You switched documents.
You quit Word.

No comments: