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.
This is a very useful article
thanks
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
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
I just realized what’s happening. This website is removing indentations. The script I posted above had indentations in several lines. IF those indentations are used in VBA, the compile error goes away. Here’s where I found the indented version:
http://www.pixelchef.net/content/rule-autosave-attachment-outlook
You are right!
I’ve changed the text now and the quotes seem ‘normal’ again.
Thanks!
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?
Hmm, not that i know of.
I am running Outlook as Administrator on the server 🙂
Where do I find the saveFolder? I didn’t change the name or anything. Searched C and found nothing.
Maybe you don’t have access to create a folder on C:\.
Try something like C:\Users\\Documents
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?
Try to first create the folder ‘temp’ on C:\
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?