Outlook VBA Script: Download All Attachments From Outlook Folder

Created by Art Bryman, Modified on Mon, 7 Jul at 11:49 AM by Art Bryman

In Outlook, press "ALT + F11" to open VBA Editor.
Click Insert > Module
Copy code below into Module
Replace "C:\Attachments" with the correct folder name in savePath


Sub DownloadAllAttachmentsLateBinding()
    Dim ns As Object
    Dim olFolder As Object
    Dim olItem As Object
    Dim olAtmt As Object
    Dim savePath As String
    Dim fileName As String
    Dim i As Integer

    savePath = "C:\Attachments"

    Set ns = Application.GetNamespace("MAPI")
    Set olFolder = ns.PickFolder

    If olFolder Is Nothing Then
        MsgBox "No folder selected. Exiting.", vbExclamation
        Exit Sub
    End If

    i = 0
    For Each olItem In olFolder.Items
        If olItem.Class = 43 Then ' 43 = MailItem
            For Each olAtmt In olItem.Attachments
                fileName = savePath & "\" & olAtmt.FileName
                olAtmt.SaveAsFile fileName
                i = i + 1
            Next olAtmt
        End If
    Next olItem

    MsgBox "Downloaded " & i & " attachments to " & savePath, vbInformation
End Sub


Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article