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 detach or save, click Kutools > Detach All or Save All based on your needs.
2. In the next opening dialog box, you need to:
- Choose a folder to save the attachments;
- Select a subfolder style as you need (Optional);
- Specify the attachments with certain extensions you will detach or save only (Optional);
Tips: If you only want to detach or save word document attachments, please check the Only detach or save attachments with following extensions boxes, enter .docx into the text box. For multiple extensions, please use “;” to separate them, such as .docx;.txt.
- Click the OK button. See screenshot:
3. In the next popping up dialog box, click Yes to continue.
Then all attachments in selected emails are detached or saved into the specified folder at once.
- 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.