PDA

View Full Version : Solved: Rule triggering macro fails



KilianD
02-19-2013, 01:37 AM
Hello,
I have this fine macro that, when triggered by a rule, saves attachment and calls the excel macro to process the saved file. The rule also marks the email as read and moves it to the bin. It works fine when single email is received or when I run the rule manually. However, when I receive bunch of emails in the morning, the rule fires, marks the email as read, moves it to the bin and then gives me message "Rule failed" without further details.
This is the code:

Public Sub saveAttachtoDisk(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String

saveFolder = "C:\Users\E9752888\Desktop\"
For Each objAtt In itm.Attachments
objAtt.SaveAsFile saveFolder & "\" & objAtt.DisplayName
Set objAtt = Nothing
Next
CallExcelMacro
End Sub

Sub CallExcelMacro()
Dim eApp As Excel.Application
Set eApp = GetObject(, "Excel.Application")
eApp.run "PERSONAL.XLSB!ANDULA_BDCPO"
Response = MsgBox("CSV ready for upload", 0)
End Sub

Any suggestion will be greatly appreciated.

skatonni
02-19-2013, 06:53 PM
You can use Rules, ItemAdd and NewMailEx. Rules are the most unreliable.

If you are not aware of NewMailEx see here http://msdn.microsoft.com/en-us/library/office/bb147646(v=office.12).aspx

KilianD
02-22-2013, 01:48 AM
Hello skatonni,
thanks for the hint. I am now able to capture and evaluate incoming email using event NewMailEx. I am still having troubles putting it all together, but it is now very different story from my original request, so I am marking this thread as closed.
Thank you again for your help