Sign in to follow this  
Followers 0
AskMrStone

Variable must be of type "Object"

12 posts in this topic

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.Visible

When 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^ ERROR

I 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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Any other suggestions?

Maybe it's a security issue?

Share this post


Link to post
Share on other sites

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!

:shocked:


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

Share this post


Link to post
Share on other sites

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!

:shocked:

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

Share this post


Link to post
Share on other sites

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.

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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Þ~ÞZ­q©È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Â

Share this post


Link to post
Share on other sites

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...

CODE
cs ----------------------------------------------------------------------------

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

Share this post


Link to post
Share on other sites

Oulook is different. Use run to start it then ObjGet(....

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0