How to save attachments without opening the email in Outlook?
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.
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 & "\" Else 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 xAttachment.Delete If xMailItem.BodyFormat <> olFormatHTML Then xOriginalFiles = xOriginalFiles & vbCrLf & "file://" & xFileName Else 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 Else xMailItem.HTMLBody = "<p>" & "The file(s) were saved to " & xOriginalFiles & "</p>" & xMailItem.HTMLBody End If xMailItem.Save End If Next 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("http://schemas.microsoft.com/mapi/proptag/0x3712001F") 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.
If you are a newbie in VBA, the method in this section will be your good choice.
1. Select the emails containing the attachments you will save, click Kutools > Attachment Tools > Save 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.
- Auto CC/BCC by rules when sending email; Auto Forward Multiple Emails by custom; Auto Reply without exchange server, and more automatic features...
- BCC Warning - show message when you try to reply all if your mail address is in the BCC list; Remind When Missing Attachments, and more remind features...
- Reply (All) With All Attachments in the mail conversation; Reply Many Emails in seconds; Auto Add Greeting when reply; Add Date into subject...
- Attachment Tools: Manage All Attachments in All Mails, Auto Detach, Compress All, Rename All, Save All... Quick Report, Count Selected Mails...
- Powerful Junk Emails by custom; Remove Duplicate Mails and Contacts... Enable you to do smarter, faster and better in Outlook.