Juvigy Posted October 22, 2013 Posted October 22, 2013 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 ?
water Posted October 22, 2013 Posted October 22, 2013 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 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
Juvigy Posted October 22, 2013 Author Posted October 22, 2013 Do u mean i should create a VBA in Outlook and do a - Shellexecute(myexe.exe 'param1') ? Or convert my outoit to VBA and create it in outlook and dont use a autoit script?
water Posted October 22, 2013 Posted October 22, 2013 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 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
Juvigy Posted October 22, 2013 Author Posted October 22, 2013 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.
water Posted October 22, 2013 Posted October 22, 2013 There is no property named "FileName" for a mailitem object. 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
water Posted October 22, 2013 Posted October 22, 2013 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 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
Juvigy Posted October 22, 2013 Author Posted October 22, 2013 Great , after fixint the small mistakes it works now. Thanks for the help. Just curious - can this be done with AutoIt somehow ? Rule to pass object to a AutoIT exe file ?
water Posted October 22, 2013 Posted October 22, 2013 (edited) 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 October 22, 2013 by water 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
Juvigy Posted October 22, 2013 Author Posted October 22, 2013 You mean a rule which starts an application ? This works , but how to pass mail object (or any object) to that application ?
water Posted October 22, 2013 Posted October 22, 2013 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 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
Juvigy Posted October 29, 2013 Author Posted October 29, 2013 I tested it - it doesnt pass parameters.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now