VBOffice

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: 64.515  | #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
  Else
    Set Sel = Application.ActiveExplorer.Selection
    For i = 1 To Sel.Count
      coll.Add Sel(i)
    Next
  End If

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

  Shell "Explorer.exe /n, /e, " & Path, vbNormalFocus
End Sub
Reporter Reporter
VBOffice Reporter is an easy to use tool for data analysis and reporting in Outlook. A single click, for instance, allows you to see the number of hours planned for meetings the next month.
email  Send a message