Automatically download Outlook attachments

Automatically download Outlook attachments to folder using VBA and Outlook rule

To achieve this automation which automatically download and save Outlook attachments to a chosen folder, you need to create a VBA script and run this script with a rule to. Please do as follows:

  1. Press Alt + F11 keys to open the Microsoft Visual Basic for Applications window.
  2. Click Insert > Module, and then paste below VBA script into the new opening Module window.

VBA: Auto Save Outlook Attachments into a certain folder

          Public Sub SaveOutlookAttachmentsToDisk(MItem As Outlook.MailItem)
Dim oOutlookAttachment As Outlook.Attachment
Dim sSaveAttachmentsFolder As String
sSaveAttachmentsFolder = “ D:\ServerReports\outlook-attachments\
For Each oOutlookAttachment In MItem.Attachments
oOutlookAttachment.SaveAsFile sSaveAttachmentsFolder &                   oOutlookAttachment.DisplayName
Next
End Sub

Note: You can replace the destination folder’s path as you need. Above code looks as

1

Fig.1

 

  1. Save the VBA Script and close the Microsoft Visual Basic for Applications window.
  2. Go to the Mail view, and click Home > Rules > Manage Rules & Alerts. See screenshots:

2

Fig.2

 

3

Fig.3

 

This selection is optional. If you do not wish to download all attachments, you can select conditions from Fig.4.

4

Fig.4

 

5

Fig.5

 

6

Fig.6

 


Unable to see run a script option in outlook?

a. Right Click on desktop (or any desired folder location) New > New text document.
b. Copy – Paste registry code as shown. (Code in text is given below Fig.7)
c. Save as .reg file with the contents below. (You can give any name)

7

Fig.7

 

I. Outlook 2016

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Outlook\Security]

“EnableUnsafeClientMailRules”=dword:00000001

 

ii. Outlook 2013

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Outlook\Security]

“EnableUnsafeClientMailRules”=dword:00000001

 

iii. Outlook 2010

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Outlook\Security]

“EnableUnsafeClientMailRules”=dword:00000001

d. Run the .reg file as an admin

8

Fig.8

 

f. Restart outlook. (Rebooting in case it do not show)


Back to Attachment process.

6
Fig.6 (Repeat)

 

9

Fig.9

 

10

Fig.=10

 

4. Close the Rules and Alerts dialog box.

And now all/desired attachments are downloaded from your email account and saved into the specified destination folder.

Keep reading, share your thoughts, experiences. Feel free to contact us to discuss more. If you have any suggestion / feedback / doubt, you are most welcome.

Stay tuned on Knowledge-Junction, will come up with more such articles.

Thanks for reading 🙂

 

13 thoughts on “Automatically download Outlook attachments

  1. Your solution is great, but for Outlook 2016 (for example), will be much easier to configure a Flow to download all your attachments to OneDrive. I have done that and for me it’s perfect 🙂 Just thought I would throw this out there

  2. I really appreciate the write up. Really helpful. Found another useful tool on internet, SysTools Outlook Attachment Extractor to download attachments from outlook automatically.

  3. Any idea why the option to check the box for ‘run a script’ wouldn’t show up? This is the perfect solution for what I need and I don’t where to go from here.

      1. Yes, unfortunately, the Run a Script option is disabled by default now, so this is no longer possible for those who don’t want to go digging in the registry.

        Alternatives welcomed!?

  4. Does anyone know whether it is possible to change the name of the file attachment being saved in the process? We have a requirement where an app produces attachments with random file names which we would ideally like to convert to something meaningful as we download them…

    1. Easy. Just edit the bit of code at the start to have the name you want:

      oOutlookAttachment.SaveAsFile sSaveAttachmentsFolder &
      OutlookAttachment.DisplayName

      can become

      oOutlookAttachment.SaveAsFile sSaveAttachmentsFolder &
      format(date(),”yymmdd”) & ” – Important File” & left(OutlookAttachment.DisplayName,4)

      this would save as

      200916 – Important File.txt

This site uses Akismet to reduce spam. Learn how your comment data is processed.