This is a great little script to help you automate sorting targeted emails in Outlook and removing the attachments for processing or storage in your document repository. The instructions are for sorting invoice emails that arrive but can be tailored for any type of email you choose.
From within Outlook (IMPORTANT!) bring up the VBA editor window by pressing ALT+F11
Right click on the Project1 item and go to Insert > Module
When the code editor window opens, paste the below code in:
Remember to change the following statement in the [ ] brackets to reflect the shared folder you would like the attachments to be copied to:
ie: saveFolder = "[yourFolderLocation]"
eg: saveFolder = "S:\Docs\ToProcess"
Attribute VB_Name = "Module1"
Public Sub saveAttachtoDisk(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
dateFormat = Format(Now, "yyyy-mm-dd_H-mm-ss")
saveFolder = "[yourFolderLocation]"
For Each objAtt In itm.Attachments
objAtt.SaveAsFile saveFolder & "\" & dateFormat & objAtt.DisplayName
Set objAtt = Nothing
Your project should look like this:
Click Save and close the Microsoft Visual Basic for Applications window.
Now to create the rule that will use this script, in Outlook go to Home ribbon > Rules > Manage Rules and Alerts
Select the New Rule button
Select the Apply rule on messages I receive option and click Next
These next steps can be configured any way you like and some parameters can be left out if it doesn’t suite your business needs.
Step 1: Select Conditions
Check with specific words in the subject
Which has an attachment
Step 2: Edit the Rule description
Click on the Specific Words link and type in each word that you want this rule to look for in a subject of an email such as: Invoice, Invoices, Invoicing etc. (click Add after each word to add them separately)
NOTE: Please tailor this to your specific needs as you will know what details to use as filter parameters based on what information your clients send you.
Step 1: Select Action(s)
Check move it to a Specified Folder
Check run a script
Step 2: Edit the rule description
Click on the specified folder link
Select the folder you want to move the email to (This is recommended so that you can easily see that it’s been processed rather than having to compare whats in a folder and whats in your Inbox to see if an email hasn’t been processed)
Click on the Run a script link
Select the script we just created called Project1.saveAttachtoDiskRule
Step 1: Select Exception(s) (if necessary)
I chose to NOT process reply emails which saves processing of the same file if people respond to the same email conversation, so select except if the subject contains specific words
Type in re: to exempt replied or responded emails from this rule (you can tailor this to your business need)
Click Next, review your rule and then click Finish when you are satisfied that it’s correct.