Jump to content

Access Outlook Public Folder via COM


Recommended Posts

I'm finding that COM support in Auto-It just isn't cutting it. I'm trying to access contents in a public folder. Below is my converted code from VB to Auto-It. VB works fine and hopefully I can get this to run in Auto-It with a little help.

Any help would be much appreciated and revive my confidence in the program.

Thanks

Dim $objApp
Dim $objNS
Dim $colFolders
Dim $objFolder

;Substitute MyPublicFolder for one that exists on your system
_GetFolder ("Public Folders\All Public Folders\MyPublicFolder")

;Return count of items in folder
msgbox(0,"test",$objFolder.Items.Count)


Func _GetFolder($strFolderPath)
    Dim $arrFolders
    Dim $i

    $arrFolders = StringSplit($strFolderPath, "\")
    $objApp = ObjCreate("Outlook.Application")
    $objNS = $objApp.GetNamespace("MAPI")
    $objFolder = $objNS.Folders.Item($arrFolders[1])


    If  stringlen($objFolder)>0 Then
        For $i = 2 To $arrFolders[0]
            $colFolders = $objFolder.Folders
            $objFolder = $colFolders.Item($arrFolders[$i])
            If stringlen($objFolder)=0 Then
                ExitLoop
            EndIf
        Next
    EndIf

    $GetFolder = $objFolder
EndFunc
Link to comment
Share on other sites

I'm finding that COM support in Auto-It just isn't cutting it. I'm trying to access contents in a public folder. Below is my converted code from VB to Auto-It. VB works fine and hopefully I can get this to run in Auto-It with a little help.

Any help would be much appreciated and revive my confidence in the program.

Thanks

Func _GetFolder($strFolderPath)
    ; ...
    If  stringlen($objFolder)>0 Then
        ; ...
    EndIf

    $GetFolder = $objFolder
EndFunc
So... you're testing the StringLen() of an object variable... and this function returns what...???

Oh, well. You should just give up. COM object methods must be way over AutoIt's head! <_<

:D

P.S. I am appropriately ashamed of myself for sarcasm and rude laghter.

:"> :):P:lol::lol::lol::lol::)

P.P.S. ...ahem. Shame on me.

Edited by PsaltyDS
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
Link to comment
Share on other sites

Link to comment
Share on other sites

Hopefully this will restore your faith in AutoIt. It is obviously a new language for you and there are conventions and syntax you need to absorb. Note the IsObj test and how to return values from a function.

BTW, the Count property returned 0 and I didn't go and study the object model docs -- .Name is returning an appropriate value. Need to check your item count syntax.

#AutoIt3Wrapper_run_debug_mode=Y

Dim $objApp
Dim $objNS
Dim $colFolders
Dim $objFolder

;Substitute MyPublicFolder for one that exists on your system
$oFolder = _GetFolder ("Public Folders\All Public Folders\MyFolder")

;Return count of items in folder
;msgbox(0,"test",$oFolder.Items.Count)
msgbox(0,"test",$oFolder.Name)


Func _GetFolder($strFolderPath)
    Dim $arrFolders
    Dim $i

    $arrFolders = StringSplit($strFolderPath, "\")
    $objApp = ObjCreate("Outlook.Application")
    $objNS = $objApp.GetNamespace("MAPI")
    $objFolder = $objNS.Folders.Item($arrFolders[1])
    ConsoleWrite(ObjName($objFolder) & @CR)

    If  IsObj($objFolder) Then
        For $i = 2 To $arrFolders[0]
            $colFolders = $objFolder.Folders
            $objFolder = $colFolders.Item($arrFolders[$i])
            If Not IsObj($objFolder) Then
                ExitLoop
            EndIf
        Next
    EndIf

    Return $objFolder
EndFunc

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

First, I apologize as my problem was not clearly stated. From DaleHohm's example and the rude laughter of PsaltyDS I corrected my script and was able to get it to work. isObj did the trick

As suggested, I have also added COM Error handling to the script.

Just to get a second opinion, using a variable ByRef is not supported in AutoIt, correct?

If you also want a more worthy problem of mine (related to Crystal Reports Viewer COM object) that is better explained, check out the following: DateParameter

Again I appreciate your help, especially as I failed to clearly state my problem.

Link to comment
Share on other sites

I've seen Internet explorer UDFs which used Byrefs in their parameters in the help file examples, if that means anything.

Inserting shameless help topic advertisement:

Speaking of the IE UDFs, Dale, aren't you the one who wrote them? Maybe you could help me in the thread I recently made in this section? <_<Never mind. Thanks Psalty.

Edited by Nevin
Link to comment
Share on other sites

First, I apologize as my problem was not clearly stated. From DaleHohm's example and the rude laughter of PsaltyDS I corrected my script and was able to get it to work. isObj did the trick

As suggested, I have also added COM Error handling to the script.

Wahoo!

Just to get a second opinion, using a variable ByRef is not supported in AutoIt, correct?

You really need to start reading the help file, or there WILL be more rude laughter!

Func...Return...EndFunc

--------------------------------------------------------------------------------

Defines a user-defined function that takes zero or more arguments and optionally returns a result.

Func functioname ( [Const] [byRef] $param1, ..., [Const] [byRef] $paramN, $optionalpar1 = value, ...)

...

[Return [value]]

EndFunc

Remarks

The ByRef keyword is optional and means: (1) the parameter must a variable, and (2) the original variable is linked to the parameter, so that any changes to the parameter inside the function, would affect the original variable as well. By default, a parameter is passed by value which means that a copy of the parameter's value, is manipulated by the function.

The order of the ByRef and Const keywords is not important, so long as they are in front of the variable they modify.

<_<
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
Link to comment
Share on other sites

Yes, read the docs, but in this case they don't tell the whole story. byRef is certainly supported in AutoIt, but object variables are treated as byVal even when passed byRef. To my knowledge this is not in the docs, only in recent discussions here in the forum.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...