Jump to content

OutlookEX - needed an "always create new" parameter


Recommended Posts

I had a problem using OutlookEX when automating Outlook v14 (2010) when it was already running; the object returned from _OL_Open wasn't usable .

As a test, this example would fail to create an object for $objMail but there was no error from _OL_Open()

$outlook = _OL_Open()
$objMail = $outlook.Application.CreateItem(0)

but this replacement would work:

$outlook = ObjCreate("Outlook.Application")
$objMail = $outlook.Application.CreateItem(0)

and this would fail:

$outlook = ObjGet("", "Outlook.Application")
$objMail = $outlook.Application.CreateItem(0)

So for my own purposes, the "fix" was to just to add a flag for _OL_Open() to ObjCreate() instead of ObjGet() when needed, setting it to True when there's a problem

Func _OL_Open($bCreateNew = False, $bWarningClick = False, $sWarningProgram = "", $iWinCheckTime = 1000, $iCtrlCheckTime = 1000, $sProfileName = "", $sPassword = "")

    If $bCreateNew = Default Then $bCreateNew = False
    If $bWarningClick = Default Then $bWarningClick = False
    If $sWarningProgram = Default Then $sWarningProgram = ""
    If $iWinCheckTime = Default Then $iWinCheckTime = 1000
    If $iCtrlCheckTime = Default Then $iCtrlCheckTime = 1000
    If $sProfileName = Default Then $sProfileName = ""
    If $sPassword = Default Then $sPassword = ""
    Local $oOL = ObjGet("", "Outlook.Application")
    If IsObj($oOL) Then $__bOL_AlreadyRunning = True
    If Not IsBool($bWarningClick) Then Return SetError(3, 0, 0)
    If Not IsInt($iWinCheckTime) Then Return SetError(4, 0, 0)
    If Not IsInt($iCtrlCheckTime) Then Return SetError(7, 0, 0)
    If $__bOL_AlreadyRunning And $sProfileName <> "" Then Return SetError(10, 0, 0) ;Specified a profile name to logon to but Outlook is already running.
    ; Activate the COM error handler for older AutoIt versions
    If $__iOL_Debug = 0 And (Number(StringReplace(@AutoItVersion, ".", "")) < 3392 Or Number(StringReplace(@AutoItVersion, ".", "")) > 33120) Then
        _OL_ErrorNotify(4)
        SetError(0) ; Reset @error which is returned by _OL_ErrorNotify if a COM error handler has already been set up by the user
    EndIf
    If Not $__bOL_AlreadyRunning Or $bCreateNew Then
        $oOL = ObjCreate("Outlook.Application")
        If @error Or Not IsObj($oOL) Then Return SetError(1, @error, 0)
    EndIf

 

However, the problem with modifying a UDF is in remembering to apply the same fix for to any update

Was there any other "fix" I should have tried before tampering with the UDF?

Thanks.

 

Link to comment
Share on other sites

On 6/11/2019 at 6:15 PM, Tippex said:

I had a problem using OutlookEX when automating Outlook v14 (2010) when it was already running; the object returned from _OL_Open wasn't usable .

As a test, this example would fail to create an object for $objMail but there was no error from _OL_Open()

$outlook = _OL_Open()
$objMail = $outlook.Application.CreateItem(0)

Define: "wasn't usable". Did you test that it was an object with IsObj?
What is the value of @error and @extended after _OL_Open?

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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

×
×
  • Create New...