;Include the following Constants: #include #include #include AutoItSetOption("WinTitleMatchMode", 2) ;COM Error Handling ;tried to implement but no success ;Global $oMyError = ObjEvent("AutoIt.Error", "ErrorFunc") ; Install a custom error handler ;Global $g_eventerror = 0 ; to be checked to know if com error occurs. Must be reset after handling. ;Do AD queries ;Open Word doc and insert text.... $oWordApp1 = _WordCreate(@ScriptDir & "\Test", 0, 1, 1) If @error Then Switch @error Case 1 ;FileWriteLine($file, " Exiting Program - Error Code: " & @error) Case 3 ;FileWriteLine($file, " Exiting Program - Error Code: " & @error) Case 4 ;FileWriteLine($file, " Exiting Program - Error Code: " & @error) EndSwitch Exit EndIf $oDoc1 = _WordDocGetCollection($oWordApp1, 0) If @error Then Switch @error Case 3 ;FileWriteLine($file, " Exiting Program - Error Code: " & @error) Case 4 ;FileWriteLine($file, " Exiting Program - Error Code: " & @error) Case 5 ;FileWriteLine($file, " Exiting Program - Error Code: " & @error) Case 7 ;FileWriteLine($file, " Exiting Program - Error Code: " & @error) EndSwitch Exit EndIf $oDoc1.Range.insertAfter("Insert some text here...." & @CRLF) Sleep(5000) _WordDocSave($oDoc1) If @error Then Switch @error Case 1 ;FileWriteLine($file, " Exiting Program - Error Code: " & @error) Case 3 ;FileWriteLine($file, " Exiting Program - Error Code: " & @error) Case 4 ;FileWriteLine($file, " Exiting Program - Error Code: " & @error) EndSwitch Exit EndIf ProcessClose("winword.exe") Exit Func ErrorFunc() ;Custom error handler $HexNumber=hex($oMyError.number,8) Msgbox(0,"","We intercepted a COM Error !" & @CRLF & _ "Number is: " & $HexNumber & @CRLF & _ "Windescription is: " & $oMyError.windescription ) $g_eventerror = 1 ; something to check for when this function returns Endfunc