Auto Download Outlook Email Attachment – Code in VBA by

Topbullets.comI get some raw data through email every day. Now when I want to do some analysis on the data I need to go through the inbox, search for that particular data and then download it to local. The process is very tedious. Now I am very happy that I have got rid of this manual process. Kudos to Google! I want to share the tutorial with very basic code. One can easily leverage the VBA code to write some complicated criteria and enhance it further. Here I am using snapshots from Outlook 2013 but have tested the feature in 2007 and was working fine. Without talking too much let’s start.

Step 1: Open your Outlook and enable micro.

File>>Option>> Trust Center>> Trust center settings>> Select notification for all macros


Step 2: Then press Alt+F11 to open VBA. Go to ‘Module’ from left panel or you can add one new one if you don’t see it there.

Step 3: Paste the below code and save it.

Public Sub SaveAutoAttach(item As Outlook.MailItem)

Dim object_attachment As Outlook.Attachment

Dim saveFolder As String
' Folder location when I want to save my file
saveFolder = "D:\Data\Archive"

    For Each object_attachment In item.Attachments
' Criteria to save .doc files only
    If InStr(object_attachment.DisplayName, ".doc") Then

        object_attachment.SaveAsFile saveFolder & "\" & object_attachment.DisplayName

    End If


End Sub

Step 4: Now Go to Rule>>Manage Rules & Alerts. Please follow below snapshots.


Step 5: Select ‘Apply rule on message I receive’ and Next


Step 6: In this step choose your words sincerely. Right now I am choosing 2nd option. Whatever you select on the first panel you will see them in 2nd panel. Click on ‘Specific word’ circled in the image.


Step 7: Provide the word like “IBM Data” and save it. You can add more words as well.

Step 8: In this step we will select ‘Action’. As we want to run a VBA script, we select ‘run a script’. Again click on ‘run a script’; a pop-up windows may open. Just ‘Enable’ the micros and select the micro which we saved in backend.



Step 9: You are almost done. Save the rule as per your convenience and click ‘Finish’. Select the circled check box if you want to run the script on deleted items otherwise it’s good.

Step 10: Restart your outlook and send some document with subject ‘IBM Data’ and see the magic.


Deepesh Singh


9 thoughts on “Auto Download Outlook Email Attachment – Code in VBA by

  1. Hi I have pasted the above code in outlook module & when i setting rule, i am not getting open of “Run a script”.
    how can i find it, let me know if there is any option to show it.

  2. hi, i was curious on how the code would fit ( InStr ) if you wanted to have it for more than two file extenstions.
    Like .xlsx or .pdf along with .doc put in.

  3. very useful code, but i have problem
    problem is file send with same file name so old file deleted and replaced by new one.
    need to add date for file name
    thanks for you

Please leave your valuable comment.

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s