Save outlook attachments

From UBC Wiki

Exporting your attachments from your outlook to a folder

1) Make sure you have the proper folders, go into your local drive C:

outlook export attachment

2) Go into Users

outlook export attachment

3) Go into your currently logged in Profile (This computer account is lfsuser)

outlook export attachment

4) Go into Documents

outlook export attachment

5) There should be an Attachments folder here, this is where the email attachments are saved to. If there is no Attachments folder, create a folder with the name Attachments

outlook attachment


6) Now open outlook and click on the Developer tab and click on Visual Basics, if this tab doesn't exist follow the next few steps, otherwise skip to step 10

outlook attachment

7) Click on File

outlook attachment

8) Go to Options

outlook export attachment

9) Go to Customize Ribbons and make sure the Developer box is checked

outlook export attachment

10) Now exit and go back and click on Developer and then Visual Basics

outlook attachment

11) Click on Insert and then Module

outlook export attachment

12) Copy the following code into the box, it should look something like this

outlook attachment

Public Sub SaveAttachments()
Dim objOL As Outlook.Application 
Dim objMsg As Outlook.MailItem 'Object 
Dim objAttachments As Outlook.Attachments 
Dim objSelection As Outlook.Selection 
Dim i As Long 
Dim lngCount As Long 
Dim strFile As String 
Dim strFolderpath As String 
Dim strDeletedFiles As String 
strFolderpath = CreateObject("WScript.Shell").SpecialFolders(16)
On Error Resume Next
Set objOL = CreateObject("Outlook.Application")
Set objSelection = objOL.ActiveExplorer.Selection
strFolderpath = strFolderpath & "\Attachments\"
For Each objMsg In objSelection
   Set objAttachments = objMsg.Attachments
   lngCount = objAttachments.Count
   strDeletedFiles = ""
   If lngCount > 0 Then
       For i = lngCount To 1 Step -1
           strFile = objAttachments.Item(i).FileName
           strFile = strFolderpath & strFile
           objAttachments.Item(i).SaveAsFile strFile
           If objMsg.BodyFormat <> olFormatHTML Then
               strDeletedFiles = strDeletedFiles & vbCrLf & "<file://" & strFile & ">"
           Else
               strDeletedFiles = strDeletedFiles & "<br>" & "<a href='file://" & _ 
               strFile & "'>" & strFile & "</a>"
           End If
       Next i
       If objMsg.BodyFormat <> olFormatHTML Then
           objMsg.Body = vbCrLf & "The file(s) were saved to " & strDeletedFiles & vbCrLf & objMsg.Body
       Else
           objMsg.HTMLBody = "<p>" & "The file(s) were saved to " & strDeletedFiles & "</p>" & objMsg.HTMLBody
       End If
       objMsg.Save
   End If
Next
ExitSub:
Set objAttachments = Nothing
Set objMsg = Nothing
Set objSelection = Nothing
Set objOL = Nothing
End Sub

13) Now Go to File and then Save and exit

outlook export attachment

14) To export the attachments, select the emails that you want to export the attachments (CTRL+A to select all), and then click Developer then Macros then Save.Attachments

outlook attachment

15) Your files will be saved to the Attachments folder

outlook attachment


Source: http://stackoverflow.com/questions/15531093/save-attachments-to-a-folder-and-rename-them