Jump to content

OutlookEX UDF


water
 Share

Recommended Posts

Sure :)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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

On 5/12/2016 at 9:03 AM, water said:

Hey guys,

seems the UDF gets used by some of you :)
Is there anything missing (functions in the UDF, examples, tutorials in the wiki ...)?

Hey water :)

The UDF is used A LOT! Can't do without it, so thank you for your work with it, and for always taking your time to help us out with it!
Can't think of any functions missing atm, but will let you know if I think of any.

- David

Link to comment
Share on other sites

Thanks! I'm glad you like the UDF and that it helps you in your job.
I will be glad to provide further functions if the need arises!

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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

On 28/10/2016 at 2:56 PM, water said:

I would add _OL_Open and then check the returned error:

#RequireAdmin
#include <OutlookEX.au3>

Global $oOL = _OL_Open()
If @error Then
    ; Log the error etc.
    Exit
EndIf
_OL_MailSignatureSet("name", "name")
; ...
_OL_Close($oOL)
Exit

 

Thanks water :)

I'm still struggling a little with the _OL_MailSignatureSet regarding troubleshooting.
It works 99% of the time, but some times it seems that a user opens the compiled AutoIt script with different elevated rights, than Outlook was opened with.
At least that's my guess, since they get an error referring to a line that doesn't exist in the original script, but in the OutlookEX UDF.

I can, as we spoke of earlier, reproduce the error just as a test, by adding #RequireAdmin. In your example above, I get Error "1" in the log.
At least with the error check I prevented the error message, which is good, but using _OL_Open is not preferable in my script, since it can give some problems if the user manually opens Outlook while _OL_Open is called. This will cause Outlook to close again.

Since _OL_Open isn't needed for the _OL_MailSignatureSet function to work, is there a way to avoid the error message, and write it to the log, without using _OL_Open? :)

Link to comment
Share on other sites

As _OL_MailSignatureSet does not need Outlook you could simply drop _OL_Open.

BTW: The problem you encounter is described here.

Edited by water
Add problem description

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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

1 hour ago, water said:

As _OL_MailSignatureSet does not need Outlook you could simply drop _OL_Open.

BTW: The problem you encounter is described here.

Yeah that's what I wrote :) 

 

4 hours ago, david1337 said:

Since _OL_Open isn't needed for the _OL_MailSignatureSet function to work, is there a way to avoid the error message, and write it to the log, without using _OL_Open? :)

I have already read the debugging section from your link. My question is, how do I find the error code, and stop the error message, when I don't use _OL_Open?

Thanks :)

Link to comment
Share on other sites

You even get the error message when you just use _OL_MailSignatureSet?
Can you please post the error messages you get from the SciTE output pane?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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

Yeah I do, but only if I have Outlook opened, and this is because Outlook is opened with another permission. This I know.
Now I just want to stop the error message when it happens to a user.

The weird thing is that if I run the script in SciTE, there is no error message, but the _OL_MailSignatureSet function doesn't work either.

You can reproduce the error if you:

1. Compile this script:

#include <OutlookEX.au3>
#RequireAdmin

_OL_MailSignatureSet("NameOfSig", "NameOfSig")

2. Open your Outlook

3. Run your compiled script.

Then you should get a line error.

Thanks for your time btw!

Link to comment
Share on other sites

Will check tomorrow :)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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

_OL_MailSignatureSet calls _OL_MailSignatureGet to check if the specified signature exists.
When #Requireadmin is set then the script is executed as the Admin user. This user doesn't have any signatures  (not even the default). This situation is not handled by _OL_MailSignatureSet and hence it crashes.

I suggest to end your script if it is run as admin:

#RequireAdmin
If IsAdmin() Then Exit MsgBox($MB_SYSTEMMODAL, "", "Do not run this script with admin rights!")

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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

Hi water

Thanks for you answer!

Of course the "#RequireAdmin" is not included in the actual script. I just added it to simulate a situation where the compiled exe ran with different rights than Outlook.
So IF this is the case with those users, that the line error they get from the OutlookEX UDF is caused by running as admin, then I've got that covered now at least.

If it's something else from the _OL_MailSignatureSet function that gives the error, then I cannot get en error code telling me what it is. Is that correct understood? :)

Link to comment
Share on other sites

It's something in _OL_MailSignatureGet which gets called by _OL_MailSignatureSet.
I will need to modify _OL_MailSignatureGet to properly handle this errors and report them back to the calling function which then should properly handle this error and report it back to the calling script.

I will test this new version with #RequireAdmin and post the modified code ASAP.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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

Replace this two modified functions in your OutlookEX UDF and you should get @error = 3, @extended = 6 when trying to set a signature with @RequireAdmin.
If this is true then please test with another invalid user and lets see what you get.

; #FUNCTION# ====================================================================================================================
; Name ..........: _OL_MailSignatureGet
; Description ...: Returns a list of e-mail signatures used when you create/edit e-mail messages and replies.
; Syntax.........: _OL_MailSignatureGet([$sSignature = ""[, $oWord = 0]])
; Parameters ....: $sSignature - Optional: Name of a signature to check for existance. The result contains this single signature or is set to error.
;                  $oWord      - Optional: Object of an already running Word Application (default = 0 = no Word Application running)
; Return values .: Success - two-dimensional one based array with the following information:
;                  |0 - Name of the signature
;                  |1 - True if the signature is used when creating new messages
;                  |2 - True if the signature is used when replying to a message
;                  Failure - Returns "" and sets @error:
;                  |1 - Error accessing Word object. For details check @extended
;                  |2 - Specified signature does not exist
;                  |3 - Error accessing Word EmailOptions object. For details check @extended
;                  |4 - Error accessing Word EmailSignature object. For details check @extended
;                  |5 - Error accessing Word EmailSignatureEntries object. For details check @extended
;                  |6 - Error accessing property NewMessageSignature. For details check @extended
;                  |7 - Error accessing property ReplyMessageSignature. For details check @extended
; Author ........: water
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _OL_MailSignatureGet($sSignature = "", $oWord = 0)

    Local $bWordStart = False
    Local Const $wdDoNotSaveChanges = 0 ; Do not save pending changes
    If $oWord = 0 Then
        $oWord = ObjCreate("Word.Application")
        $bWordStart = True
    EndIf
    If @error Or Not IsObj($oWord) Then Return SetError(1, @error, "")
    Local $oEmailOptions = $oWord.EmailOptions
    If @error Or Not IsObj($oEmailOptions) Then Return SetError(3, @error, "")
    Local $oSignatureObject = $oEmailOptions.EmailSignature
    If @error Or Not IsObj($oSignatureObject) Then Return SetError(4, @error, "")
    Local $oSignatureEntries = $oSignatureObject.EmailSignatureEntries
    If @error Or Not IsObj($oSignatureEntries) Then Return SetError(5, @error, "")
    Local $sNewMessageSig = $oSignatureObject.NewMessageSignature
    If @error Then Return SetError(6, @error, "")
    Local $sReplyMessageSig = $oSignatureObject.ReplyMessageSignature
    If @error Then Return SetError(7, @error, "")
    Local $aSignatures[$oSignatureEntries.Count + 1][3]
    Local $iIndex = 0
    For $oSignatureEntry In $oSignatureEntries
        If $sSignature = "" Or $sSignature == $oSignatureEntry.Name Then
            $iIndex = $iIndex + 1
            $aSignatures[$iIndex][0] = $oSignatureEntry.Name
            If $aSignatures[$iIndex][0] = $sNewMessageSig Then
                $aSignatures[$iIndex][1] = True
            Else
                $aSignatures[$iIndex][1] = False
            EndIf
            If $aSignatures[$iIndex][0] = $sReplyMessageSig Then
                $aSignatures[$iIndex][2] = True
            Else
                $aSignatures[$iIndex][2] = False
            EndIf
        EndIf
    Next
    ReDim $aSignatures[$iIndex + 1][3]
    $aSignatures[0][0] = $iIndex
    $aSignatures[0][1] = UBound($aSignatures, 2)
    If $bWordStart = True Then
        $oWord.Quit($wdDoNotSaveChanges)
        $oWord = 0
    EndIf
    If $sSignature <> "" And $aSignatures[0][0] = 0 Then Return SetError(2, 0, "")
    Return $aSignatures

EndFunc   ;==>_OL_MailSignatureGet

; #FUNCTION# ====================================================================================================================
; Name ..........: _OL_MailSignatureSet
; Description ...: Sets the signature to be added to new email messages and/or when you reply to an email message.
; Syntax.........: _OL_MailSignatureSet($sNewMessage, $sReplyMessage[, $oWord = 0])
; Parameters ....: $sNewMessage   - Name of the signature to be added to new email messages. "" removes the default signature. Keyword Default leaves the signature unchanged
;                  $sReplyMessage - Name of the signature to be added when you reply to an email messages. "" removes the default signature. Keyword Default leaves the signature unchanged
;                  $oWord         - Optional: Object of an already running Word Application (default = 0 = no Word Application running)
; Return values .: Success - 1
;                  Failure - Returns 0 and sets @error:
;                  |1 - $oWord is not an object or MS Word could not be started when $oWord = 0
;                  |2 - Error accessing Word EmailOptions object. For details check @extended
;                  |3 - $sNewMessage could not be found in the list of already defined signatures. @extended is set to the value of @error as returned by _OL_MailSignatureGet
;                  |4 - $sReplyMessage could not be found in the list of already defined signatures. @extended is set to the value of @error as returned by _OL_MailSignatureGet
;                  |5 - Error accessing Word EmailSignature object. For details check @extended
;                  |6 - Error setting property NewMessageSignature. For details check @extended
;                  |7 - Error setting property ReplyMessageSignature. For details check @extended
; Author ........: water
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _OL_MailSignatureSet($sNewMessage, $sReplyMessage, $oWord = 0)

    Local $bWordStart = False, $iError = 0
    Local Const $wdDoNotSaveChanges = 0 ; Do not save pending changes
    If $oWord = 0 Then
        $oWord = ObjCreate("Word.Application")
        $bWordStart = True
    EndIf
    If @error Or Not IsObj($oWord) Then Return SetError(1, @error, "")
    ; Check if the specified signatures exist
    If $sNewMessage <> Default And $sNewMessage <> "" Then
        _OL_MailSignatureGet($sNewMessage, $oWord)
        If @error Then
            $iError = @error
            If $bWordStart = True Then
                $oWord.Quit($wdDoNotSaveChanges)
                $oWord = 0
            EndIf
            Return SetError(3, $iError, 0)
        EndIf
    EndIf
    If $sReplyMessage <> Default And $sReplyMessage <> "" Then
        _OL_MailSignatureGet($sReplyMessage, $oWord)
        If @error Then
            $iError = @error
            If $bWordStart = True Then
                $oWord.Quit($wdDoNotSaveChanges)
                $oWord = 0
            EndIf
            Return SetError(4, $iError, 0)
        EndIf
    EndIf
    ; Set Signatures
    Local $oEmailOptions = $oWord.EmailOptions
    If @error Or Not IsObj($oEmailOptions) Then Return SetError(2, @error, 0)
    Local $oSignatureObject = $oEmailOptions.EmailSignature
    If @error Or Not IsObj($oSignatureObject) Then Return SetError(5, @error, 0)
    #forceref $oSignatureObject
    If $sNewMessage <> Default Then
        $oSignatureObject.NewMessageSignature = $sNewMessage
        If @error Then Return SetError(6, @error, 0)
    EndIf
    If $sReplyMessage <> Default Then
        $oSignatureObject.ReplyMessageSignature = $sReplyMessage
        If @error Then Return SetError(7, @error, 0)
    EndIf
    If $bWordStart = True Then
        $oWord.Quit($wdDoNotSaveChanges)
        $oWord = 0
    EndIf
    Return 1

EndFunc   ;==>_OL_MailSignatureSet

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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

I use this modified version to get @error and @extended and it works fine. But it takes about 40 seconds to display the MsgBox. Don't know why.

#include <OutlookEX.au3>
#RequireAdmin

_OL_MailSignatureSet("NameOfSig", "NameOfSig")

If @error Then
   MsgBox(0,"","@error: " & @error & @CRLF & "@extended: " & @extended)
EndIf

Are you sure your script grabs the correct version of the UDF?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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

Hi everybody!

I have a very simple task but cant get it work(

What i need is to copy or move every item in one foder to another. 

For example: i have two folders inbox1 & inbox2

i need to copy everything (all massages and subfolders) from inbox2 to inbox1. Whatever i do, the only thing i could make is to copy or move a folder itself to another.  Can i kindly ask you for help?

 

Thank you!

Link to comment
Share on other sites

12 minutes ago, water said:

I use this modified version to get @error and @extended and it works fine. But it takes about 40 seconds to display the MsgBox. Don't know why.

#include <OutlookEX.au3>
#RequireAdmin

_OL_MailSignatureSet("NameOfSig", "NameOfSig")

If @error Then
   MsgBox(0,"","@error: " & @error & @CRLF & "@extended: " & @extended)
EndIf

Are you sure your script grabs the correct version of the UDF?

Yeah, it grabs the correct UDF. Just double checked!


If I remove #RequireAdmin, and change the name of the signature to something that doesn't exist, I get:
@error: 3
@extended: 2
 

With #RequireAdmin I get nothing from SciTE and Line error from compiled - as always. So weird. Maybe because of our different Windows versions?
I'm on Win 10 Ent x64
Office 2013
 

Link to comment
Share on other sites

I just tried to turn things around, and start Outlook as administrator, and then NOT run script as administrator.
This gives me the exact same line error in the compiled version, but at least here SciTE shows this error:

"C:\Program Files (x86)\AutoIt3\Include\OutlookEX.au3" (4283) : ==> The requested action with this object has failed.:
Local $sNewMessageSig = $oSignatureObject.NewMessageSignature
Local $sNewMessageSig = $oSignatureObject^ ERROR

 

My MsgBox with the error code did not pop up, it justt crashed with the above message: :(

Edited by david1337
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...