Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save DataSolveProblems/48424a5272c5e2b143e030d4d32ea480 to your computer and use it in GitHub Desktop.
Save DataSolveProblems/48424a5272c5e2b143e030d4d32ea480 to your computer and use it in GitHub Desktop.
Sub Download_Attachments()
Dim ns As NameSpace
Dim olFolder_Inbox As Folder
Dim olMail As MailItem
Dim olAttachment As Attachment
Dim fso As Object
Dim Files_Saved_Folder_Path As String
Files_Saved_Folder_Path = "<Your folder path>"
Set ns = GetNamespace("MAPI")
Set fso = CreateObject("Scripting.FileSystemObject")
Set olFolder_Inbox = ns.GetDefaultFolder(olFolderInbox)
For Each olMail In olFolder_Inbox.Items
If TypeName(olMail) = "MailItem" And olMail.Attachments.Count > 0 Then
fso.CreateFolder (fso.BuildPath(File_Saved, Trim(olMail.Subject)))
For Each olAttachment In olMail.Attachments
olAttachment.SaveAsFile fso.BuildPath(File_Saved, Trim(olMail.Subject)) & "\" & olAttachment.FileName
Next olAttachment
End If
Next olMail
Set olFolder_Inbox = Nothing
Set fso = Nothing
Set ns = Nothing
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment