Jump to content

Outlook Rules and Attachments issues


Juvigy
 Share

Recommended Posts

When working with OutlookEx udf i get a strange error:

 

err.description is:     The operation failed.
err.windescription:    
err.number is:     80020009
err.lastdllerror is:     0
err.scriptline is:     1681
err.source is:     Microsoft Outlook
err.helpfile is:     
err.helpcontext is:     0

My script is 50 lines so this must be in some of the iclude files.

What i am trying to do:

I have a rule in outlook that should move a mail in my pst and run a exe file to download the attachment to a folder.

It all works for one mail. But when i receive 2 or 3 mails almost at the same time the script fails and downloads only one attachment.

I use:

$myItem2 = $myFolder[1].Items.GetLast()
$myItem3 = $myItem2.attachments(1)
$myItem3.saveasfile($Filepath & $myItem3.FileName )

And what happens is that when the rule move 3 mails and executes the exe file , the 3 exe files get one and the same mail and download only 1 attachment instead of 3. What can i do to pass somehow a parameter to the exe file on which mail to execute ?

Link to comment
Share on other sites

When the Outlook rule is defined to run a script then the object of the mail is passed as a parameter to the script.

This means you can directly access/process the item in your script.

Link

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

I've never done something like this myself. I would suggest the solution that is easier for you to implement.

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

Sub SaveAttachment(MyMail As MailItem)

    Dim strID As String

    Dim objMail As Outlook.MailItem

    FilePath = "C:111"

    strID = MyMail.EntryID

    Set objMail = Application.Session.GetItemFromID(strID)

    If objMail.FileName = "222.xlsx" Then objMail.Attachments(1).SaveAsFile (FilePath & objMail.FileName)

    objMail.Attachments(1).SaveAsFile (FilePath & "111" & Month(Now()) & Day(Now()) & ".xlsx")

    Set objMail = Nothing

End Sub

 

This is the VBA script  that i created and attached to the rule. When i a new mail arrive , it is moved by the rule to a pst but it doesnt save the file.

Link to comment
Share on other sites

There is no property named "FileName" for a mailitem object.

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

I think you could strip down your code because the function gets the object of the mailitem:

Sub SaveAttachment(MyMail As MailItem)
    FilePath = "C:\111\"
    If MyMail.Attachments(1).FileName = "222.xlsx" Then MyMail.Attachments(1).SaveAsFile (FilePath & MyMail.FileName)
    MyMail.Attachments(1).SaveAsFile (FilePath & "111" & Month(Now()) & Day(Now()) & ".xlsx")
End Sub

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

I have Outlook 2010 installed and it allows to run an application when a mail is received (in German: "Anwendung starten").

But unfortunately I don't know which parameters Outlook passes.

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

I don't know if Outlook passes the item that triggered the rule to the application. Compile an AutoIt script that writes the number and type of parameters to a MsgBox:

If $CmdLine[0] > 0 Then
    MsgBox(0, "Parameters", "# of parameters: " & $CmdLine[0] & "Typ of parameter 1: " & VarGetType($CmdLine[1]))
Else
    MsgBox(0, "Parameters", "No parameters passed!")
EndIf

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

  • Recently Browsing   0 members

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