Save Multiple Attachments to the File System

This sample saves the attachments of all selected emails to the file system.

Last modified: 2012/07/29 | Accessed: 66.005  | #93
◀ Previous sample Next sample ▶
Category-Manager Category-Manager
With Category-Manager you can group your Outlook categories, share them with other users, filter a folder by category, automatically categorize new emails, and more. You can use the Addin even for IMAP.

This example saves all attachments of the selected items to the harddisk. The path assigned to the Path variable must yet exist. The macro automatically creates a subfolder in that directory named with the current date. Eventually the Windows file explorer will be opened with that new directory.

tip  How to add macros to Outlook
Public Sub SaveAttachments2()
  Dim coll As VBA.Collection
  Dim obj As Object
  Dim Att As Outlook.Attachment
  Dim Sel As Outlook.Selection
  Dim Path$
  Dim i&

  Path = "d:\"
  Path = Path & Format(Date, "yyyy-mm-dd") & "\"
  On Error Resume Next
  MkDir Path
  On Error GoTo 0

  Set coll = New VBA.Collection

  If TypeOf Application.ActiveWindow Is Outlook.Inspector Then
    coll.Add Application.ActiveInspector.CurrentItem
    Set Sel = Application.ActiveExplorer.Selection
    For i = 1 To Sel.Count
      coll.Add Sel(i)
  End If

  For Each obj In coll
    For Each Att In obj.Attachments
      Att.SaveAsFile Path & Att.FileName

  Shell "Explorer.exe /n, /e, " & Path, vbNormalFocus
End Sub
Determine the "identity" of your emails. Set with SAM the sender and the folder folder for sent items with the help of rules.
email  Send a message