Below code is to save email attachment to a local folder. The trigger is by outlook rules. However, occasionally there will be “An unexpected error has occurred.” from Rules in Error and the code will not work as expected. The file name is standardised and will be sent daily as csv only. File name eg: Report0311.csv
Code that I’ve tried:
Sub SaveAttachmentsToFolder(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
saveFolder = “C:\Users\Me\Home\SaveFolder\”
For Each objAtt In itm.Attachments
obiAtt.SaveAsFile saveFolder & “\” & objAtt.DisplayName
Next
End Sub
objAtt.DisplayName
have any illegal characters in it when you get the error? There are some characters that cannot be used in a filename.Report0311.csv
what it actually is when you get the error? Or is that what you think it's supposed to always be? In order to see the actual value, you need to click debug when you get the error and check your variables while it is paused.