Rule to autosave attachment in Outlook

Here's a cool trick. This provides a way to automatically save attachments of emails as they arrive. I have tested this in Outlook 2007.

  1. Open the VBA IDE in Outlook. Alt-F11 will do this.
  2. Insert the following code to the Modules section. On the left side there is a tree, expand until you find Modules. Then, if there is not a Module item under Modules, create one by right clicking on Modules. Now past the following code in the main VBA window.
  3. Close the VBA IDE.
  4. Create a Rule that calls the script. Tools -> Rules and Alerts -> New Rule...
  5. In the first screen of the new rule wizard, choose "Check messages when they arrive".
  6. In the second, you could specify certain criteria that the message must match. Tip: Try "with specific words in the message header" and ".txt" for the search string to save only .txt files.
  7. On the third screen, choose "run a script". When you click the underlined word, "script", you should see the code that you pasted in the VBA console.
  8. Click "finish", and test your work.
If this was helpful to you, drop me a note in the comments below.

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

Comments

incremental number at the end

This code great but I often get emails with attachments that have the same name resulting in overwriting the older attachment. What code could I add so that the new attachment coming in with the same name would add an incremental number at the end?
 
TY
Mike

You could concatenate a

You could concatenate a timestamp onto the end of the file name. I'm not very familiar with VBA myself, but I know it's possible. Google is your friend.

To clarify, this would be

To clarify, this would be instead of an incremental number. It would be a lot more work to keep track of an incremental number, but a timestamp is not even one extra line of code.

Awesome

By far the simplest solution to the problem I have seen. Thanks for the great tip!

Auto Save Outlook Attachment Rule

I have tried it and for some reason, my files are saving as Gif? What is weired is some save as xxls but the majority are gif. what can I do to fix?

attachment save?

The script runs but wondering where the attachments are saved? If you can help in this it will be great!

Attachment save location

Carefully read through the code, line-by-line, and you'll find a variable that tells you were it is saved. If you want to change it, just change the value of the variable on the right side of the equal sign.

And it worked like a charm.

And it worked like a charm.

Legend, this is exactly what

Legend, this is exactly what I've been looking for.

Post new comment

The content of this field is kept private and will not be shown publicly.

More information about formatting options