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:
- Press Alt + F11 keys to open the Microsoft Visual Basic for Applications window.
- 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
Fig.1
- Save the VBA Script and close the Microsoft Visual Basic for Applications window.
- Go to the Mail view, and click Home > Rules > Manage Rules & Alerts. See screenshots:
Fig.2
Fig.3
This selection is optional. If you do not wish to download all attachments, you can select conditions from Fig.4.
Fig.4
Fig.5
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)
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
Fig.8
f. Restart outlook. (Rebooting in case it do not show)
Back to Attachment process.
Fig.6 (Repeat)
Fig.9
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 🙂
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
Thanks albandrod for sharing one more option. But I guess then user will need Office 365 license for using flow (Office 365 feature). And case might be that users might have Outlook but not Office 365.
Thank you Albandrod for your candour in exceptional technical suggestion. I will try your suggestion shortly and add to this blog. 🙂
I really appreciate the write up. Really helpful. Found another useful tool on internet, SysTools Outlook Attachment Extractor to download attachments from outlook automatically.
Thanks a lot! 🙂
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.
Unable to see run a script option in outlook?
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!?
Thumb Up! You made my day
I tried this. The process is complete. Rule is created and implemented but the attachments are not getting stored.
Hi Robin, Microsoft Visual Basic for Applications window is not supported in my office laptop
Is there any alternate option for Visual Basic?
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…
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