Save Outlook Attachments to Disk

Jul 15
2013

I used the code on this page for a client to save the attachments into a specific folder

The files that are saved are automatically unzipped and loaded into a database each night and the system creates the reports automatically and loads the report PDFs into a MS Sharepoint server for access through the WAN

http://www.pixelchef.net/content/rule-autosave-attachment-outlook

I changed the code slightly as all the files were zipped with the same name and I used the email subject and date to distinguish the files.

Public Sub saveAttachtoDisk (itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String, DateFormat
 
DateFormat = Format(Now(), "yyyy-mm-dd H-mm")
 
saveFolder = "C:\temp"
 
    For Each objAtt In itm.Attachments
        objAtt.SaveAsFile saveFolder & "\" & itm.Subject & "_" & DateFormat & objAtt.DisplayName
        Set objAtt = Nothing
    Next
 
End Sub

Leave a Reply

You must be logged in to post a comment.

If you need some help on a project drop leave a comment on the post and I will reply.