22

Someone sent me 200 emails overnight, with one file attachment apiece. sigh

I'm expecting another 200 each night for the next three nights (the emails come from a server, so asking them to batch them isn't possible).

The file attachments have unique filenames, so is there a straightforward way to save the attachments from the entire group of emails at once?

I'd hate to have to open each email individually, right click, save, rinse, repeat...

I'm fluent in VBA, very comfortable creating Excel macros, so I can imagine it should be relatively easy to traverse a given folder for all messages and save attachments for each, but I haven't written an Outlook macro before, not familiar with the object hierarchy.

5 Answers 5

20

NirSoft's OutlookAttachView can do this easily, even from the command line!

OutlookAttachView scans all messages stored in your Outlook, and displays the list of all attached files that it finds. You can easily select one or more attachments and save all of them into the desired folder, as well as you can delete unwanted large attachments that take too much disk space in your mailbox. You can also save the list of attachments into xml/html/text/csv file.

alt text

OutlookAttachView is freeware.

3
  • 1
    Thanks for this utility. Helped with what I wanted to do this morning: download 99 pdf attachments in my inbox in a go. Commented Apr 12, 2016 at 23:31
  • 1
    Works well for office 365 outlook
    – AutoBaker
    Commented Oct 29, 2021 at 11:15
  • 1
    Works while outlook is open! Very nice. Commented Nov 7, 2021 at 15:57
6

Outlook Attachment Remover Add-in:

Free Outlook add-in for saving and extracting attachments, decreasing the size of your Outlook files. Easy-to-use. Plenty of features.

image

1
  • 1
    This did not work on Outlook 2013. The add-in is simply nowhere to be found, and not recognised when I attempted to load it manually.
    – Milind R
    Commented Oct 30, 2017 at 7:15
3

Here are some more options with this.

Sue Mosher's site http://slipstick.com is a fantastic resource for Outlook. She is also a Microsoft MVP as well.

For you coders out there: Save Attachments to the hard drive and alternatively Save and Open an Attachment using VBA.

The following code works in Outlook 2000 and up. It saves the attachments from selected messages but does not delete the attachments from the message(s).

Copy and paste the code from this page into your ThisOutlookSession project.

In Outlook, press Alt+F11 to open the VBA editor and expand Microsoft Outlook Objects then double click on ThisOutlookSession to open it in the editing pane and Ctrl+V to paste the code.

To use it you must first create a folder under your My Documents named OLAttachments (the code will not create it for you). Then select one or more messages and run the macro to save the attachments. You'll need to set macro security to warn before enabling macros or sign the macro. You can change the folder name or path where the attachments are saved by editing the code.

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

    ' Get the path to your My Documents folder
    strFolderpath = CreateObject("WScript.Shell").SpecialFolders(16)
    On Error Resume Next

    ' Instantiate an Outlook Application object.
    Set objOL = CreateObject("Outlook.Application")

    ' Get the collection of selected objects.
    Set objSelection = objOL.ActiveExplorer.Selection

' The attachment folder needs to exist
' You can change this to another folder name of your choice

    ' Set the Attachment folder.
    strFolderpath = strFolderpath & "\OLAttachments\"

    ' Check each selected item for attachments. 
    For Each objMsg In objSelection

    Set objAttachments = objMsg.Attachments
    lngCount = objAttachments.Count

    If lngCount > 0 Then

    ' Use a count down loop for removing items
    ' from a collection. Otherwise, the loop counter gets
    ' confused and only every other item is removed.

    For i = lngCount To 1 Step -1

    ' Get the file name.
    strFile = objAttachments.Item(i).FileName

    ' Combine with the path to the Temp folder.
    strFile = strFolderpath & strFile

    ' Save the attachment as a file.
    objAttachments.Item(i).SaveAsFile strFile

    Next i
    End If

    Next

ExitSub:

Set objAttachments = Nothing
Set objMsg = Nothing
Set objSelection = Nothing
Set objOL = Nothing
End Sub

And if you don't want to program: Attachment Management Tools for Outlook

1
  • In my case all my emails had the same subject line so each filesave overwrote the previous one, leaving me with one single file. The quick and dirty fix I did was to prepend an index number so every file is guaranteed unique, like this: below the current declarations add: Dim Index As Long and next line Index = 1 Change: strFile = strFolderpath & strFile to strFile = strFolderpath & Index & "_" & strFile and before "Next i" add: Index = Index + 1
    – Stax
    Commented Jul 9, 2019 at 1:13
0

After I was bombed with e-mails from a person who thought it was nice to send me a split RAR file in 30 mails, I've successfully used this VBA script published by Microsoft called mAttachmentSaver.

First, you have to download the archive containing the script.

It's important that macros are enabled. In Outlook 2010, you can do that by going to File » Options » Trust Center » Trust Center Settings » Macro Settings » Enable all macros » OK » OK. Then you need to restart Outlook. For earlier versions, it's under Tools » Macro » Security….

Then, follow the steps outlined in the TechCenter article:

  • Press Alt+F11 to open the VBE in Outlook.

  • Drag the mAttachmentSaver.bas file to the Project Explorer (Press Ctrl+R if you cannot see it) or via File >> Import File... (Ctrl+M).

    Run the ExecuteSaving macro to save attachments.

  • Go back to Outlook UI, and then press Alt+F8 to open the Macros window.

  • Select ExecuteSaving in the names list, and then click the Run button (Please remember to select Outlook item(s) before running this macro).

  • Select a specific folder to save attachments from Browse For Folder dialog box, and then click the OK button.

0

Old post but I feel like it is still relevant up to this day. Here is the code that Chatgpt helped me write. It saves all attachments from multiple emails (pdfs, etc..) and saves & renames them with random numbers into your pc folder which must be called 'OLATTACHMENTS'. This permits up to 250 saves as outlook freezes for about 2 minutes when i reach that high up. Here is the code, which must be placed into developer--visual basic:

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
    
    ' Get the path to your My Documents folder
    strFolderpath = CreateObject("WScript.Shell").SpecialFolders(16)
    On Error Resume Next
    
    ' Instantiate an Outlook Application object.
    Set objOL = CreateObject("Outlook.Application")
    
    ' Get the collection of selected objects.
    Set objSelection = objOL.ActiveExplorer.Selection
    
    ' The attachment folder needs to exist
    ' You can change this to another folder name of your choice
    ' Set the Attachment folder.
    strFolderpath = strFolderpath & "\OLAttachments\"
    
    ' Check each selected item for attachments.
    For Each objMsg In objSelection
        Set objAttachments = objMsg.Attachments
        lngCount = objAttachments.Count
        
        If lngCount > 0 Then
            ' Use a count down loop for removing items
            ' from a collection. Otherwise, the loop counter gets
            ' confused and only every other item is removed.
            For i = lngCount To 1 Step -1
                ' Get the file name.
                strFile = objAttachments.Item(i).FileName
                
                ' Generate a unique file name by appending a timestamp and a random number
                Dim timestamp As String
                timestamp = Format(Now, "yyyymmddhhmmss")
                Dim randomNumber As Integer
                randomNumber = Int((9999 - 1000 + 1) * Rnd + 1000)
                Dim fileExtension As String
                fileExtension = Right(strFile, Len(strFile) - InStrRev(strFile, "."))
                strFile = Left(strFile, InStrRev(strFile, ".") - 1) & "_" & timestamp & "_" & randomNumber & "." & fileExtension
                
                ' Combine with the path to the Temp folder.
                strFile = strFolderpath & strFile
                
                ' Save the attachment as a file.
                objAttachments.Item(i).SaveAsFile strFile
            Next i
        End If
    Next objMsg
    
ExitSub:
    Set objAttachments = Nothing
    Set objMsg = Nothing
    Set objSelection = Nothing
    Set objOL = Nothing
End Sub 

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .