Skip to main content

How to save attachments without opening the email in Outlook?

Author: Siluvia Last Modified: 2021-03-03

You may frequently need to save attachments from the received emails to your computer discs. It is easy to save an attachment or all attachments from an email message, but how to save attachments from multiple emails at once? Normally, you need to repeatedly open the emails and save the attachments. Is there any tricks to get rid of the repeatedly operations? Here the methods in this tutorial can help you.

Save attachments from one or more emails without opening with VBA code
Save attachments from one or more emails without opening with an amazing tool

Save attachments from one or more emails without opening with VBA code

The below VBA code can help to save attachments from one or more emails at the same time without opening the emails in Outlook. Please do as follows.

1. Select an email or multiple emails which you will save the attachments, press the Alt + F11 keys to open the Microsoft Visual Basic for Applications window.

2. Expand the Microsoft Outlook Objects folder, double click the ThisOutlookSession to open the Code window, and then copy the below VBA code into the it.

VBA code: Save attachments without opening the emails

Public Sub SaveAttachmentsWithoutOpening()
'Updated by Extendoffice 20191008
Dim xMailItem As Outlook.MailItem
Dim xAttachments As Outlook.Attachments
Dim xAttachment As Outlook.Attachment
Dim i As Long
Dim xCount As Long
Dim xFileName As String
Dim xSavePath As String
Dim xOriginalFiles As String
On Error Resume Next
Set xShell = CreateObject("Shell.Application")
Set xFolder = xShell.BrowseForFolder(0, "Select a folder:", 0, strStartingFolder)
If Not TypeName(xFolder) = "Nothing" Then
    Set xFolderItem = xFolder.self
    xSavePath = xFolderItem.Path & "\"
    xFileName = ""
    Exit Sub
End If
For Each xMailItem In Outlook.ActiveExplorer.Selection
    Set xAttachments = xMailItem.Attachments
    xCount = xAttachments.Count
    xOriginalFiles = ""
    If xCount > 0 Then
        For i = xCount To 1 Step -1
            Set xAttachment = xAttachments.Item(i)
            If IsEmbeddedAttachment(xAttachment) = False Then
                xFileName = xSavePath & xAttachment.FileName
                xAttachment.SaveAsFile xFileName
                If xMailItem.BodyFormat <> olFormatHTML Then
                    xOriginalFiles = xOriginalFiles & vbCrLf & "file://" & xFileName
                    xOriginalFiles = xOriginalFiles & "<br>" & "<a href='file://" & xFileName & "'>" & xFileName & "</a>"
                End If
            End If
        Next i
        If xMailItem.BodyFormat <> olFormatHTML Then
            xMailItem.Body = "The file(s) were saved to " & xOriginalFiles & vbCrLf & vbCrLf & xMailItem.Body
            xMailItem.HTMLBody = "<p>" & "The file(s) were saved to " & xOriginalFiles & "</p>" & xMailItem.HTMLBody
        End If
    End If
Set xAttachments = Nothing
Set xMailItem = Nothing
End Sub

Function IsEmbeddedAttachment(Attach As Attachment)
Dim xItem As MailItem
Dim xCid As String
Dim xID As String
Dim xHtml As String
On Error Resume Next
IsEmbeddedAttachment = False
Set xItem = Attach.Parent
If xItem.BodyFormat <> olFormatHTML Then Exit Function
xCid = ""
xCid = Attach.PropertyAccessor.GetProperty("")
If xCid <> "" Then
    xHtml = xItem.HTMLBody
    xID = "cid:" & xCid
    If InStr(xHtml, xID) > 0 Then
        IsEmbeddedAttachment = True
    End If
End If
End Function

4. Press the F5 key to run the code. Then a BrowseForFolder window pops up, please select a folder to save the attachments, and then click the OK button.

Then all attachments in selected emails are saved into the selected folder immediately.

Note: All attachments will be detached from the emails and keep the corresponding saving path links in the email body.

Save attachments from one or more emails without opening with an amazing tool

If you are a newbie in VBA, the method in this section will be your good choice.

Here recommend the Save All attachments utilities of Kutools for Outlook for you. If you just want to save the attachments without detaching from selected emails, the Save All attachments feature can help you easily get it done. Please do as follows.
Before applying Kutools for Outlook, please download and install it firstly.

1. Select the emails containing the attachments you will save, click Kutools > Attachment ToolsSave All.

2. In the Save Settings dialog box, you need to:

  • 2.1) In the Save attachment(s) to this folder section, choose a folder to save the attachments;
  • 2.2) The Save attachment(s) in below style box is optional for you to create a subfolder with certian style to save the attachments, or rename the saved attachments with certian style.
  • 2.3) Click OK to start saving all attachmentsn from selected emails.

Tips: With the above configurations, all attachments will be saved into the specified folder. If you only want to save some certian attachments such as only save the PDF files with certian word "invoice" in the file name, you can configure the filter conditions as follows.  

  • Click the Advanced options button to expand the Filter conditions;
  • Specify the conditions based on your needs.
    Tips: Here I check the Attachment name contains box and then enter "invoice" into the text box, then check the Attachment type box, enter ".pdf" into the textbox.

3. In the next popping up dialog box, click Yes to continue.

Then attachments in selected emails are saved into the specified folder at once.

Tips: For detaching attachments from selected emails and leaving only the attachment hyperlinks in the email body, the Detach All attachments feature can help.

  If you want to have a free trial (30-day) of this utility, please click to download it, and then go to apply the operation according above steps.

Related articles

Automatically download/save attachments from Outlook to a certain folder
Generally speaking, you can save all attachments of one email with clicking Attachments > Save All Attachments in Outlook. But, if you need to save all attachments from all received emails and receiving emails, any ideal? This article will introduce two solutions to automatically download attachments from Outlook to a certain folder.

Keep attachments when replying in Outlook
When we forward an email message in Microsoft Outlook, original attachments in this email message are remained in the forwarded message. However, when we reply an email message, the original attachments will not be attached in the new reply message. Here we are going to introduce a couple of tricks about keeping original attachments when replying in Microsoft Outlook.

Search words within attachment (content) in Outlook
When we typing a keyword in the Instant Search box in Outlook, it will search the keyword in emailsโ€™ subjects, bodies, attachments, etc. But now I just need to search the keyword in attachment content only in Outlook, any idea? This article shows you the detailed steps to search words within attachment content in Outlook easily.

Comments (0)
No ratings yet. Be the first to rate!
There are no comments posted here yet
Leave your comments
Posting as Guest
Rate this post:
0   Characters
Suggested Locations