Auto Download Outlook Email Attachment – Code in VBA by Topbullets.com

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

TrustCenter

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

    Next

End Sub

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

Pic1

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

Pic2

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.

Pic3

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

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.

Pic5

Pic6

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

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

Signature

Deepesh Singh
logo

Please leave your valuable comment.

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s