Here's a cool trick. If you receive a lot of email attachments, maybe it would be useful to save them to My Documents or some other location on your computer besides keeping them in Outlook. I can show you how to do exactly that! These instructions show you step by step how to automatically save attachments of emails as they arrive. I have tested this in Outlook 2007 and 2010.
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
If you want to prevent files from being overwritten - for instance, if you receive two emails with the same file name, and don't want the second email to overwrite the attachment that you saved from the first, add this code below the lines that begin with 'dim':
dateFormat = Format(Now, "yyyy-mm-dd H-mm")
Then replace the line that begins with 'objAtt.SaveAsFile' with this:
objAtt.SaveAsFile saveFolder & "\" & dateFormat & objAtt.DisplayName
If you want to save attachments of a certain kind only (for example, XML files), you can use this bit of code inside of the "For Each" loop (instead of the code provided above):
if InStr(objAtt.DisplayName, '.xml') ThenobjAtt.SaveAsFile saveFolder & "\" & objAtt.DisplayNameend if
If you can't get the rule to work, try adjusting your Outlook security settings:
On the File tab, choose Outlook Options to open the Outlook Options dialog box, and then click Trust Center.
Click Trust Center Settings, and then the Macro Settings option on the left.
Select Notifications for all macros and then click OK. The option allows macros to run in Outlook, but before the macro runs, Outlook prompts you to verify that you want to run the macro.
Restart Outlook for the configuration change to take effect.