Last active
May 29, 2019 05:33
-
-
Save DataSolveProblems/3a95b34778f5be88b131dce5913ebdb1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(Files_Saved_Folder_Path, Trim(olMail.Subject))) | |
For Each olAttachment In olMail.Attachments | |
Select Case UCase(fso.GetExtensionName(olAttachment.FileName)) | |
Case "XLSX", "XLSM" | |
olAttachment.SaveAsFile fso.BuildPath(Files_Saved_Folder_Path, Trim(olMail.Subject)) & "\" & olAttachment.FileName | |
Case "JPEG", "PNG", "JPG" | |
'olAttachment.SaveAsFile fso.BuildPath(Files_Saved_Folder_Path, Trim(olMail.Subject)) & "\" & olAttachment.FileName | |
Case Else | |
'skip | |
End Select | |
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