AskMrStone Posted April 13, 2007 Posted April 13, 2007 Hi, folks. New guy on the block here. Have been using AutoIT for a very short time, and I'm needing to open Outlook, search for and open a message with a specific subject, save an attachment (CSV file) to the Desktop, then close/minimize Outlook and manipulate the file with Excel. Instead of using Run, WinActivate, etc., I was hoping to use COM instead, as it seemed more programmatic and less error-prone. However, I'm running into trouble right out of the chute. My first two statements are:CODE;Open Outlook:$outlook = ObjCreate("Outlook.Application")$outlook.VisibleWhen I save and run this, though, I get the following error message in my output:CODE>Running:(3.2.2.0):C:\Program Files\AutoIt3\autoit3.exe "C:\Documents and Settings\StoneS2\Desktop\FormatMECSV.au3" C:\Documents and Settings\StoneS2\Desktop\FormatMECSV.au3 (22) : ==> Variable must be of type "Object".: $outlook.Visible $outlook^ ERRORI tried using the #include <IE.au3> at the beginning of the script, because I saw it in someone's example code somewhere. Didn't have any effect. (Couldn't imagine why it would have, but I'll try most things once.)Any ideas, folks, about what I'm doing wrong? I've hit the forums here, MSDN, the AutoIT help files, and several other sources and can't figure out what I'm doing wrong. Incidentally, I'm using Outlook 2003 on Windows XP with all the latest SPs and patches.Thanks in advance for any and all help...Shawn Stone
flyingboz Posted April 13, 2007 Posted April 13, 2007 when working with com objects, you must familiarize yourself with the object model, msdn is a good resource, as are other scripts, particularly VB6 and VBS, as they are relatively easy to port to au3. Use an error function to trap com errors, and include extensive error checking, such as If not IsObj($outlook) to ensure that you have what you think you have. Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.
AskMrStone Posted April 13, 2007 Author Posted April 13, 2007 when working with com objects, you must familiarize yourself with the object model, msdn is a good resource, as are other scripts, particularly VB6 and VBS, as they are relatively easy to port to au3.Use an error function to trap com errors, and include extensive error checking, such as If not IsObj($outlook) to ensure that you have what you think you have.Thanks for responding. Did look in MSDN. Verified what I'd already found: that the way to declare the object variable is...$outlook = ObjCreate("Outlook.Application")And I did the If Not/Then/Else statement already, too. (Obviously, the IsObj() was returning a false every time.)Any other suggestions? Am I missing an #include statement that I'm not seeing on MSDN or anywhere else? I used the Excel example in the AutoIt help, and it worked like a charm. But for whatever reason, Outlook's not going so well.At wits' end...Shawn
amokoura Posted April 13, 2007 Posted April 13, 2007 Any other suggestions?Maybe it's a security issue?
PsaltyDS Posted April 13, 2007 Posted April 13, 2007 Quoted from a Googled-up page that says: So how do we make Outlook Visible, like Word, Excel and the rest? Outlook is the only one not to have a visible property. Pick a folder and DISPLAY it, and it works for me, but there is no $Outlook.Visible method: ; Declare COM Object error handler: Global $oComError = ObjEvent("AutoIt.Error", "_ComErrFunc") ;Open Outlook: Dim Const $OutlookFolderContacts = 10 $oOutlook = ObjCreate("Outlook.Application") $oNamespace = $oOutlook.GetNamespace ("MAPI") $oContacts = $oNamespace.GetDefaultFolder ($OutlookFolderContacts) $oContacts.Display ;-------------------------------------- ; Function _ComErrFunc() ; Custom COM object error handler ;-------------------------------------- Func _ComErrFunc() Local $HexNumber = Hex($oComError.number, 8) MsgBox(16, "AutoIT COM Error", "AutoIT COM Error Occured!" & @CRLF & _ @TAB & "Error Number: " & $HexNumber & @CRLF & _ @TAB & "Line Number: " & $oComError.scriptline & @CRLF & _ @TAB & "Description: " & $oComError.description & @CRLF & _ @TAB & "WinDescription: " & $oComError.windescription) SetError(1); something to check for when this function returns EndFunc ;==>_ComErrFunc Cheers! Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
AskMrStone Posted April 14, 2007 Author Posted April 14, 2007 Quoted from a Googled-up page that says: Pick a folder and DISPLAY it, and it works for me, but there is no $Outlook.Visible method: ; Declare COM Object error handler: Global $oComError = ObjEvent("AutoIt.Error", "_ComErrFunc") ;Open Outlook: Dim Const $OutlookFolderContacts = 10 $oOutlook = ObjCreate("Outlook.Application") $oNamespace = $oOutlook.GetNamespace ("MAPI") $oContacts = $oNamespace.GetDefaultFolder ($OutlookFolderContacts) $oContacts.Display ;-------------------------------------- ; Function _ComErrFunc() ; Custom COM object error handler ;-------------------------------------- Func _ComErrFunc() Local $HexNumber = Hex($oComError.number, 8) MsgBox(16, "AutoIT COM Error", "AutoIT COM Error Occured!" & @CRLF & _ @TAB & "Error Number: " & $HexNumber & @CRLF & _ @TAB & "Line Number: " & $oComError.scriptline & @CRLF & _ @TAB & "Description: " & $oComError.description & @CRLF & _ @TAB & "WinDescription: " & $oComError.windescription) SetError(1); something to check for when this function returns EndFunc ;==>_ComErrFunc Cheers! I'll try that first thing Monday morning. Thanks for that. Would love to get my hands on the properties/methods list for Outlook similar to the functions/macros list for AutoIt. Couldn't find that on MSDN. Any clues? Thanks again, Shawn
GaryFrost Posted April 14, 2007 Posted April 14, 2007 The above errors for me also, but this works for me (Office 2003) ; Declare COM Object error handler: Global $oComError = ObjEvent("AutoIt.Error", "_ComErrFunc") ;Open Outlook: Dim Const $OutlookFolderContacts = 10 $oOutlook = ObjGet("","Outlook.Application") $oNamespace = $oOutlook.GetNamespace ("MAPI") $oContacts = $oNamespace.GetDefaultFolder ($OutlookFolderContacts) $oContacts.Display ;-------------------------------------- ; Function _ComErrFunc() ; Custom COM object error handler ;-------------------------------------- Func _ComErrFunc() Local $HexNumber = Hex($oComError.number, 8) MsgBox(16, "AutoIT COM Error", "AutoIT COM Error Occured!" & @CRLF & _ @TAB & "Error Number: " & $HexNumber & @CRLF & _ @TAB & "Line Number: " & $oComError.scriptline & @CRLF & _ @TAB & "Description: " & $oComError.description & @CRLF & _ @TAB & "WinDescription: " & $oComError.windescription) SetError(1); something to check for when this function returns EndFunc ;==>_ComErrFunc SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference.
flyingboz Posted April 14, 2007 Posted April 14, 2007 links to the object model, amazingly enough, pop right up when you google "object model" +outlook +msdn.... Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.
AskMrStone Posted April 15, 2007 Author Posted April 15, 2007 The above errors for me also, but this works for me (Office 2003) ; Declare COM Object error handler: Global $oComError = ObjEvent("AutoIt.Error", "_ComErrFunc") ;Open Outlook: Dim Const $OutlookFolderContacts = 10 $oOutlook = ObjGet("","Outlook.Application") $oNamespace = $oOutlook.GetNamespace ("MAPI") $oContacts = $oNamespace.GetDefaultFolder ($OutlookFolderContacts) $oContacts.Display ;-------------------------------------- ; Function _ComErrFunc() ; Custom COM object error handler ;-------------------------------------- Func _ComErrFunc() Local $HexNumber = Hex($oComError.number, 8) MsgBox(16, "AutoIT COM Error", "AutoIT COM Error Occured!" & @CRLF & _ @TAB & "Error Number: " & $HexNumber & @CRLF & _ @TAB & "Line Number: " & $oComError.scriptline & @CRLF & _ @TAB & "Description: " & $oComError.description & @CRLF & _ @TAB & "WinDescription: " & $oComError.windescription) SetError(1); something to check for when this function returns EndFunc ;==>_ComErrFunc oÝ÷ Ûú®¢×®ë-«b¢z^®È¬¶Â-®'Ê«{¦¦WÛaj×ë¢cìj[rljg«zË¥¶Çë¢fÞ~ÞZq©Èmçhx0®àêÞßÛ-ç^nè"úºÚ"µÍÝÉ][ÝÐÎÌLÔÙÜ[H[ÉÌLÐ]]Ò]ÉÌLÔØÚUIÌLÐ]]Ò]ÕÜÌLÐ]]Ò]ÕÜ^I][ÝÈÜ[ÜÙÑÜÝÝ]Ú[ ][ÝÐÎÌLÑØÝ[Y[È[Ù][ÜÉÌLÔÚ]ÛÌLÑÚÝÜ ÌLÓ]È]]Ò]ÈØÜ]LÉ][ÝÈØ]]Ú]Ù ][ÝÐÎÌLÔÙÜ[H[ÉÌLÐ]]Ò]É][ÝÈÕÙ[ÈÉÝÌLÎMÈÝ[È]]Ò]ÕÜKËÝÔ[[ÈULÐÚXÚÈ KM H[ÎÛNÎÌLÔÙÜ[H[ÉÌLÐ]]Ò]ÂÉÝÌLÎNULÐÚXÚÈ[YÎÝÔ[[ÎË NÎÌLÔÙÜ[H[ÉÌLÐ]]Ò]ÉÌLØ]]Ú]Ë^H ][ÝÐÎÌLÑØÝ[Y[È[Ù][ÜÉÌLÔÚ]ÛÌLÑÚÝÜ ÌLÓ]È]]Ò]ÈØÜ]LÉ][ÝÈÎÌLÑØÝ[Y[È[Ù][ÜÉÌLÔÚ]ÛÌLÑÚÝÜ ÌLÓ]È]]Ò]ÈØÜ]LÈ LÊHOIÝÈXXH]ÝHÙH ][ÝÓØXÝ ][ÝËÌÍÛ^S[YÜXÙHH ÌÍÛ^SÝ]ÛÚËÙ][YTÜXÙJ ][ÝÓPTI][ÝÊHÌÍÛ^S[YÜXÙHH ÌÍÛ^SÝ]ÛÚ×TÔÉÝÌLÎN]]ÒUË^H[YÎÉÝÌLÎNH]]Ò]ÕÜ[ÚYÝÑ^]ÛÙN[YNK MÂ
AskMrStone Posted April 16, 2007 Author Posted April 16, 2007 Thought I might have been having trouble at home this weekend due to my not having Outlook installed. So tried again at work today. Here's the code... CODEcs ---------------------------------------------------------------------------- AutoIt Version: 3.2.2.0 Author: Shawn Stone Script Function: Retrieve, format, and forward CSV file attachment from Outlook's Inbox. #ce ---------------------------------------------------------------------------- ;Start: ;Be sure only one instance is running: $g_szVersion = "My Script 1.1" If WinExists($g_szVersion) Then Exit ; It's already running AutoItWinSetTitle($g_szVersion) ;Open Outlook: Dim Const $OutlookFolderContacts = 10 $oOutlook = ObjGet("", "Outlook.Application") $oNamespace = $oOutlook.GetNameSpace("MAPI") $oContacts = $oNamespace.GetDefaultFolder ($OutlookFolderContacts) $oContacts.Display Sleep("5000") ...and the debug info... CODE>"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:\Documents and Settings\ZZZZZZZ\Desktop\AU3\FormatMECSV.au3" /autoit3dir "C:\Program Files\AutoIt3" /UserParams +>09:34:59 Starting AutoIt3Wrapper v.1.7.7 >Running AU3Check (1.54.6.0) from:C:\Program Files\AutoIt3 +>09:34:59 AU3Check ended.rc:0 >Running:(3.2.2.0):C:\Program Files\AutoIt3\autoit3.exe "C:\Documents and Settings\ZZZZZZZ\Desktop\AU3\FormatMECSV.au3" C:\Documents and Settings\ZZZZZZZ\Desktop\AU3\FormatMECSV.au3 (22) : ==> Variable must be of type "Object".: $oNamespace = $oOutlook.GetNameSpace("MAPI") $oNamespace = $oOutlook^ ERROR +>09:35:02 AutoIT3.exe ended.rc:0 +>09:35:02 AutoIt3Wrapper Finished >Exit code: 0 Time: 11.127 Any idea as to why neither this nor the ObjCreate("Outlook.Application) usage creates an object? Thanks, Shawn
ptrex Posted April 16, 2007 Posted April 16, 2007 @Maybe you can have a look at my Outlook to Excel / Word example.Might give you some ideas on what's wrong.Outlook exampleregardsptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New
RDSchaefer Posted June 28, 2007 Posted June 28, 2007 Oulook is different. Use run to start it then ObjGet(....
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now