Log in

View Full Version : Catching errors in Outlook rule running a script



fourclicks
03-09-2016, 12:23 PM
I have an outlook rule set up to run a script that automatically downloads attachments when the email is received and prepends the filename with the date, time, and a random number (to prevent overwrites with files of the same name). Every once in a while the rule will experience an error and turn itself off. I want to know what's causing the error, and I suspect it might have to do with trying to retrieve the time but I can't know for certain. My question is what would be the best way to try and track down the cause of this error?

Here's the script:

Public Sub saveAttachtoDisk(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
Dim dateFormat
dateFormat = Format(Now, "yyyy-mm-dd H-mm-ss ") & Rnd & " FILENAME = "
saveFolder = "C:\Users\User\Desktop\EFAX EMAIL\"
For Each objAtt In itm.Attachments
objAtt.SaveAsFile saveFolder & "\" & dateFormat & objAtt.DisplayName
Set objAtt = Nothing
Next
End Sub

gmayor
03-09-2016, 09:53 PM
I suspect the problem is
objAtt.DisplayName
Change to
objAtt.FileName

fourclicks
03-10-2016, 08:40 AM
So far so good! That also rings a bell because it seemed to happen more generally with certain shorter filenames like Scan.pdf. Thanks for your help!