Friday, January 16, 2015

Automatically Save Attachment in Outlook

To have Outlook automatically save an attachment when an email is received:
Open Outlook.
Press ALT-F11 to open the VBA IDE.
Right click the Microsoft Outlook Object and select Insert –> Module


Paste the following code, modify the saveFolder as appropriate:
Public Sub saveAttachtoDisk(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
saveFolder = "N:\untangleReports\"
     For Each objAtt In itm.Attachments
          objAtt.SaveAsFile saveFolder & "\" & objAtt.DisplayName
          Set objAtt = Nothing
End Sub

Save the Project and close the editor.

On the Home tab, select Rules –> Manage Rules & Alerts

Select New Rule…

Choose Apply the rule on messages I receive and click Next

Select which has an attachment and click Next

Select Run a Script, and press a script (in Step 2)

Select the saveAttachtoDisk (the project number may vary, depending on what macros you have)
and click OK

Click Finish

You may receive the following warning if you are connected to an Exchange server.  This means it is a client side rule, and Outlook must be opened for the rule to work.  Click OK.

Click OK

You can also customise the rule to configure it to only save attachments with specific subjects, specific attachment types, or from certain senders.  You can also configure Outlook to delete the email and mark it as read as well.
If you are saving the attachments to a network location, and the location doesn’t exist, the script may display an error, and Outlook may crash.  You should be able to open Outlook again and fix the network errors, or disable the rule.

No comments:

Post a Comment