Hey bigMe, I have two types of solution to your problem. The first code here will save the attachments from the sender automatically in the folder path you specify.dear friends,
is it possible using VBA to save an email's attachment from specific sender or subject to a folder? kindly help me how to do it, thank you.
regards,
bigMe
Public WithEvents objInboxItems As Outlook.Items
Private Sub Application_Startup()
Set objInboxItems = Session.GetDefaultFolder(olFolderInbox).Items
End Sub
Private Sub objInboxItems_ItemAdd(ByVal item As Object)
Dim mn_MailObj As Outlook.MailItem
Dim mn_SenderAddress As String
Dim mn_SenderDomain As String
Dim objAttachment As attachment
Dim mn_FolderPath As String
Dim mn_DesiredSender As String
mn_FolderPath = "C:\Folder Path\"
mn_DesiredSender = "[email protected]"
If item.Class = olMail Then
Set mn_MailObj = item
mn_SenderAddress = mn_MailObj.SenderEmailAddress
mn_SenderDomain = Right(mn_SenderAddress, Len(mn_SenderAddress) - InStr(mn_SenderAddress, "@"))
If mn_SenderAddress = mn_DesiredSender Then
If mn_MailObj.Attachments.Count > 0 Then
For Each objAttachment In mn_MailObj.Attachments
objAttachment.SaveAsFile mn_FolderPath & objAttachment.FileName
Next
End If
End If
End If
End Sub
Sub SaveAttachmentsFromSpecificSender()
Dim mn_namesapace As NameSpace
Dim mn_inbox As MAPIFolder
Dim mn_item As Object
Dim attachment As attachment
Dim mn_senderAddress As String
Dim mn_saveFolder As String
mn_senderAddress = "[email protected]"
mn_saveFolder = "C:\Folder Path\"
Set mn_namesapace = Application.GetNamespace("MAPI")
Set mn_inbox = mn_namesapace.GetDefaultFolder(olFolderInbox)
For Each mn_item In mn_inbox.Items
If TypeOf mn_item Is MailItem Then
If mn_item.SenderEmailAddress = mn_senderAddress Then
For Each attachment In mn_item.Attachments
attachment.SaveAsFile mn_saveFolder & attachment.FileName
Next attachment
End If
End If
Next mn_item
Set mn_namesapace = Nothing
Set mn_inbox = Nothing
Set mn_item = Nothing
Set attachment = Nothing
End Sub