Sunday, November 4, 2018

Outlook save all attachments

Save attachments from multiple selected items in Outlook (VBA)

Introduction

This VBA sample illustrates how to save attachments from multiple selected items in Outlook.

Scenarios

When multiple items are selected, the Save Attachments option in the File menu will be grayed out, and it's inconvenient to save attachments one by one. This script is useful and can be used to save attachments from multiple selected items all at once.

Script

Import the "mAttachmentSaver.bas" file.
Step1. Press Alt+F11 to open the VBE in Outlook.
Step2. 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.
Step3. Go back to Outlook UI, and then press Alt+F8 to open the Macros window.
Step4. Select "ExecuteSaving" in the names list, and then click the Run button (Please remember to select Outlook item(s) before running this macro).
Step5. Select a specific folder to save attachments from Browse For Folder dialog box, and then click the OK button.
 

Here are some code snippets for your references. To get the complete script sample, please click the Download button at the beginning of this page.
Visual Basic
' ###################################### 
' Run this macro for saving attachments. 
' ###################################### 
Public Sub ExecuteSaving() 
    Dim lNum As Long 
     
    lNum = SaveAttachmentsFromSelection 
     
    If lNum > 0 Then 
        MsgBox CStr(lNum) & " attachment(s) was(were) saved successfully.", vbInformation, "Message from Attachment Saver" 
    Else 
        MsgBox "No attachment(s) in the selected Outlook items.", vbInformation, "Message from Attachment Saver" 
    End If 
End Sub
  

Note

1. Please make sure that macros are enabled in Outlook. 
For Outlook 2010:File >> Options >> Trust Center >> Trust Center Settings >> Macro Settings >> Enable all macros >> OK >> OK >> Restart Outlook
For Outlook 2007:Tools >> Macro >> Security... >> Macro >> Security >> No security check for macros >> OK >> Restart Outlook
For Outlook 2003:Tools >> Macro >> Security... >> Macro >> Security >> Low >> OK >> Restart Outlook
2. This macro will save all attachments even those are used in the item body.
3. If the attachment file to be saved (let's call "FileA.txt") has already existed in the folder (FileA.txt, FileB.txt, FileC.txt ... and so on), the date time string will be appended to the attachment file name automatically.For example:
The "FileA.txt" file may be named as "FileA_05201830669.txt".
        "05" means the current month;
        "20" means the current day;
        "18" means the current hour;
        "30" means the current minute;
        "669" means the current millisecond.
4. In Windows file system, the specified path cannot be so long that you cannot create or save a file. The maximum path length limitation is 260 characters. So sometimes some attachments cannot be saved successfully if the specified path is over 260 characters.

Credit:

https://gallery.technet.microsoft.com/office/Save-attachments-from-5b6bf54b


download: https://gallery.technet.microsoft.com/office/Save-attachments-from-5b6bf54b/file/65122/1/mAttachmentSaver.zip