Outlook – Automatically save an outlook attachment to disk

If you want to automatically save an attachment to a folder on your computer/server do the following:

Open Outlook and open Microsoft Visual Basic for Applications (Alt + F11).
Expand the tree view on the left till you reach ThisOutlookSession, now right click on ThisOutlookSession and select insert -> module.

You will now get a blank window, copy and paste this code:

Public Sub saveAttachtoDisk (itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
saveFolder = "c:\temp\"
For Each objAtt In itm.Attachments
objAtt.SaveAsFile saveFolder & "\" & objAtt.DisplayName
Set objAtt = Nothing
Next
End Sub

Change the ‘saveFolder’ to something you want.
Save and close the Visual Basic app.

Now you will need to create a rule in Outlook that launces this script when an email arrives.

Go to Tools -> Rules and alerts -> New rule and choose Check message when they arrive -> with attachment (for example) -> run a script, click script and select your newly created VB script. Click finish and sent an test email.

If nothing is happening you probably should change the macro settings in Outlook: In Outlook go to File -> Options -> Trust center -> Trust center settings -> Macro settings and select ‘Notifications for all macros’ and click Ok.

Restart Outlook, you will get a message that your newly created script is trying to make changes to Outlook, allow that and try to send a test message again!

I tested this in Outlook 2010.

12 thoughts on “Outlook – Automatically save an outlook attachment to disk

  1. Matt Yorke

    Hi does anyone know if thei works in office 2003? i get “runtime error ’11’ division by zero” and when i click debug the line objAtt.SaveAsFile saveFolder & “ \ ” & objAtt.DisplayName is highlighted

    Reply
    1. Maria

      Matt Yorke – I get the same thing in Office 2010. The line of the script with “saveFolder” is highlighted red in Visual Basic and it shows a compile error in red. That means that line isn’t formatted correctly. The Compile Error jumps to the back slash in the “C:\temp” String (or whatever folder you changed yours to), so something is wrong with how it’s reading the backslash.

      I found this on another website. Try this instead:

      Public Sub saveAttachtoDisk(itm As Outlook.MailItem)
      Dim objAtt As Outlook.Attachment
      Dim saveFolder As String
      saveFolder = “c:\temp\”
      For Each objAtt In itm.Attachments
      objAtt.SaveAsFile saveFolder & “\” & objAtt.DisplayName
      Set objAtt = Nothing
      Next
      End Sub

      Reply
  2. Manu

    Thanks for a great handy script. I want to set this rule so it runs on server ( so, I don’t have to keep outlook running on a desktop). Is it possible to have such a rule, or any alternative to achieve the same goal?

    Reply
  3. nikki

    Where do I find the saveFolder? I didn’t change the name or anything. Searched C and found nothing? Same problem as Geo???? I have admin rights on my laptop?

    Reply
  4. Les osborne

    Thank you for making this so easy. I know this post is old but I will ask anyway. When the file is moved to the computer directory, is there a way to change the file name and possibly overwrite the same file if a previous version is there?

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Are you a human? *