;************************************************************ ;** Script: MS-Outlook automation sample script ;** Version: 0.4 ;** Created: October 9, 2000 ;** ;** Author: Ben Burnett ;** E-mail: BenBurnett@telusplanet.net ;** ;** Purpose / Comments: ;** ;** Makes a new MS-Outlook item ;** - Only tested on Office2K using Win2K ;** ;** Refrence Material used: ;** ;** 1) Microsoft Office 2000 Language Reference ;** 2) msoutl9.IDL (MS-Outlook 2000) - Generated with ;** OLE/COM Object viewer ;** ;** Known problems: ;** ;** * MS-Outlook stays resident even after we tell it ;** to close. ;************************************************************ ;************************************************************ ; Declare some global variables ; ; Outlook items that can be created with this script ; $MailItem = 0 $AppointItem = 1 $ContactItem = 2 $TaskItem = 3 $JournalItem = 4 $NoteItem = 5 $PostItem = 6 $DistListItem = 7 ; Create a new distribution list (not in my docs) ; ; Change this to whatever you want ; Dim $NewItem $NewItem = $NoteItem ; ; Common variables ; Dim $objApp ; main MS-Outlook object Dim $objItem ; our new item Dim $objInspectors ; item's 'Inspectors' object Dim $tmpObject ; general purpose temporary object holder Dim $strMessage ; general purpose variable to hold messages ;************************************************************ ; Main Script start :MAIN ; ; Script Start ; $objApp = 0 $objItem = 0 $objInspectors = 0 $tmpObject = "" ; Do some standard init. $= SetConsole("HIDE") Break on FlushKB ; Create an MS-Outlook application object ; ; NOTE: If you know for sure that Outlook 2000 installed you could ; use: "Outlook.Application.9" ; $objApp = OleCreateObject("Outlook.Application") If $objApp = 0 $strMessage = "ERROR: Failed to create MS-Outlook object" Gosub REPORT_ERROR Goto EOF ; were done EndIf ; Display version info. Dim $nVersion $nVersion = OleGetProperty($objApp, "Version") $strMessage = "You are using MS-Outlook version: " + $nVersion $= MessageBox($strMessage, "Information", 0, 2) ; Create a temporary object from the return of 'Outlook.Application.CreateItem" $tmpObject = OleCallFunc($objApp, "CreateItem", "s", "$NewItem") If $tmpObject = "" Or @ERROR <> 0 $strMessage = "ERROR: Failed to create new MS-Outlook item" Gosub REPORT_ERROR Goto EOF ; were done EndIf ; Create a _real_ object $objItem = Val("&" + $tmpObject) ; Do some simple operations if creating and 'Note' item If $NewItem = $NoteItem ; Set some properties $= OlePutProperty($objItem, "Body", "s", "Very cool script!!") EndIf ; Show the newly created MS-Outlook item If OleCallProc($objItem, "Display", "b", "0") <> 0 $strMessage = "ERROR: Could not display new item" Gosub REPORT_ERROR Goto EOF ; were done EndIf ; ; The next section of code retrieves the application's Inspectors ; colection object. Using this object we can determine how many item ; windows are currently open, in our case it will be 1. Once we ; have a reference to the inspector object we simply wait (Loop) ; till its 'Count' property decrements to zero. ; ; DEF'N: An Inspector object represents the window in which an ; item is displayed. Thus MS-Outlook's Inspectors collection ; contains a list of all the open/visible MS-Outlook windows. ; ; Grab MS-Outlook's Inspectors collection object $tmpObject = OleGetProperty($objApp, "Inspectors") If $tmpObject = "" Or @ERROR <> 0 $strMessage = "ERROR: Failed to get Inspectors collection" Gosub REPORT_ERROR Exit EndIf ; Create a _real_ object $objInspectors = Val("&" + $tmpObject) ; Wait till Outlook's Inspectors collection has no items in it While OleGetProperty($objInspectors, "Count") > 0 And @ERROR = 0 ; .. just wait... Loop ; The party is over... lets clean up before we leave. Gosub CLEAN_UP Exit ; done... ;************************************************************ ; Show the user an error, will disappear after 2 sec. :REPORT_ERROR ; Format the message Dim $strErrMsg $strErrMsg = $strMessage + Chr(10) + Chr(10) + @SERROR ; Show the error to the user $= MessageBox($strErrMsg, "ERROR!", 0, 2) ; Ignore return value, if this fails... look out your window, the sky should be falling ;) Return ; return to caller ;************************************************************ ; Clean up any objects we have created :CLEAN_UP ; ; Start the clean up ; ; Release the item's 'Inspectors' collection If $objInspectors <> 0 If OleReleaseObject($objInspectors) <> 0 $strMessage = "ERROR: Could not release the Inspectors collection" Gosub REPORT_ERROR ; .. continue with clean up ... EndIf EndIf ; Close MS-Outlook If $objApp <> 0 ; Try to quit MS-Outlook If OleCallProc($objApp, "Quit") <> 0 $strMessage = "ERROR: Could not quit MS-Outlook" Gosub REPORT_ERROR ; .. continue with clean up ... EndIf ; Release the MS-Outlook object If OleReleaseObject($objApp) <> 0 $strMessage = "ERROR: Could not release MS-Outlook object" Gosub REPORT_ERROR ; .. continue with clean up ... EndIf EndIf Return ; return to caller ;************************************************************ ; End-Of-File