Home‎ > ‎Outlook‎ > ‎

How to automatically copy Outlook attachments to a folder

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.

  1. From within Outlook (IMPORTANT!) bring up the VBA editor window by pressing ALT+F11

  2. Right click on the Project1 item and go to Insert > Module

  1. When the code editor window opens, paste the below code in:

    1. 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

Dim dateFormat

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


End Sub

  1. Your project should look like this:

  1. Click Save and close the Microsoft Visual Basic for Applications window.

  1. Now to create the rule that will use this script, in Outlook go to Home ribbon > Rules > Manage Rules and Alerts

  1. Select the New Rule button

  1. Select the Apply rule on messages I receive option and click Next

  1. 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.

  2. Step 1: Select Conditions

    1. Check with specific words in the subject

    2. Which has an attachment

  1. Step 2: Edit the Rule description

    1. 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)

      1. 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.

    2. Click Next

  1. Step 1: Select Action(s)

    1. Check move it to a Specified Folder

    2. Check run a script

  1. Step 2: Edit the rule description

    1. Click on the specified folder link

      1. 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)

    2. Click on the Run a script link

      1. Select the script we just created called Project1.saveAttachtoDiskRule

  1. Click Next

  1. Step 1: Select Exception(s) (if necessary)

    1. 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

      1. Type in re: to exempt replied or responded emails from this rule (you can tailor this to your business need)

    2. Click OK

  1. Click Next, review your rule and then click Finish when you are satisfied that it’s correct.