Sakthikumar Chinnasamy
Member
Hi All,
I need your help to save email attachment of specific subject("Backup Aging dashboard") of email which received by today.
In my official inbox, am having more than 10,000 emails. I want to search only today's received email to find the specific subject email receive or not and download the related attachments.
Below the code which I try without providing the subject
Sub Attachment_save()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim O As Outlook.Application
Dim OMAIL As Outlook.MailItem
Dim ONS As Outlook.Namespace
Dim MYFOL As Outlook.Folder
Dim atmt As Outlook.Attachment
Set O = New Outlook.Application
Set OMAIL = O.CreateItem(olMailItem)
Set ONS = O.GetNamespace("MAPI")
Set MYFOL = ONS.GetDefaultFolder(olFolderInbox)
If MYFOL.Items.Count = 0 Then
MsgBox "Automation is Empty", vbInformation, "No email Found"
End If
For Each OMAIL In MYFOL.Items
For Each atmt In OMAIL.Attachments
atmt.SaveAsFile ThisWorkbook.Path & "\" & atmt.Filename
Next
Next OMAIL
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
I need your help to save email attachment of specific subject("Backup Aging dashboard") of email which received by today.
In my official inbox, am having more than 10,000 emails. I want to search only today's received email to find the specific subject email receive or not and download the related attachments.
Below the code which I try without providing the subject
Sub Attachment_save()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim O As Outlook.Application
Dim OMAIL As Outlook.MailItem
Dim ONS As Outlook.Namespace
Dim MYFOL As Outlook.Folder
Dim atmt As Outlook.Attachment
Set O = New Outlook.Application
Set OMAIL = O.CreateItem(olMailItem)
Set ONS = O.GetNamespace("MAPI")
Set MYFOL = ONS.GetDefaultFolder(olFolderInbox)
If MYFOL.Items.Count = 0 Then
MsgBox "Automation is Empty", vbInformation, "No email Found"
End If
For Each OMAIL In MYFOL.Items
For Each atmt In OMAIL.Attachments
atmt.SaveAsFile ThisWorkbook.Path & "\" & atmt.Filename
Next
Next OMAIL
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub