Outlook – Automatically save attachments from mail matching a specific rule

emailemail-filtermicrosoft-outlook

Every morning i receive an e-mail from a person, and it contains a spreadsheet attachment. I have managed to create an outlook rule that catch these e-mails. Now, is it possible to have the attachment from each of these automatically saved into a local folder, with the filename YYYY-MM-DD.xls?

The attachment in the mail has a randomly generated filename, so it needs to take the date of when the mail is sent to pick a filename. NB: this is on my laptop, so there's a chance that the e-mail is sent on a day other than the day it is received by me (such as when it's switched off for a day), so using "todays date" is not a viable option.

EDIT:
using Windows 7 with Outlook 2013

Best Answer

To do what you want, you will need to mix a little VBA and Rules together. Not sure what version of Outlook you are using, so no guarantees here. This was tested on Outlook 2010.

This article will help you get things setup -Rule to automatically save attachment in Outlook .

The code below is modified specific to your saving the file with the name format of yyyy-mm-dd.

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

dateFormat = Format(Now, "yyyy-mm-dd")

'Change this path to the your folder location
saveFolder = "c:\temp\"

objAtt.SaveAsFile saveFolder & "\" & dateFormat & ".xls"

Set objAtt = Nothing

End Sub

Once you set up this rule to run this script, it will save any attachment from this person each time it receives one (and gives it a .xls extension). If you wish to change that, you will have to modify your rule or turn it off.

Related Question