• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to extract excel attachment from e-mail based on Subject line and e-mail received date

ThrottleWorks

Excel Ninja
Hi,

I need to extract an attachment from e-mail based on the following conditions.

1) Go to particular folder in Outlook
2) Search (partially) for subject line
3) Check if that e-mail has attachment
4) Check the e-mail received date

Extract excel file if all the four parameters mentioned above are matching.
I am new to Outlook VBA, can anyone help me in this please.

Not trying for exact answers, will be helpful if you can provide links with similar issues.
 
Check this...

You just need to change the thing here!

lNum = SaveAttachmentsFromSelection("abcd|xyz", "Archive1", "MoveFolder", False, Date)

& Set folMail = Application.GetNamespace("MAPI").Folders("xyz").Folders("Inbox")
 

Attachments

  • Save_Email_From_Outlook.txt
    11.7 KB · Views: 6
Hi @Deepak sir, sorry to disturb you on this.

I was able to change value for "Set folMail = Application.GetNamespace("MAPI").Folders("xyz").Folders("Inbox")"

I am not able to understand "("abcd|xyz", "Archive1", "MoveFolder"," this part.

What should be the values for abcd, Archive1 and MoveFolder.
I guess 'XYZ' in both the statements will remain same.

Could you please help if you get time. Good night. :)
 
sorry to disturb you on this.

Who said that, i am enjoying/learning by helping here...

I have added much comments to clear the doubts as well slightly optimized/modified the function and sub


Code:
Public Sub ExecuteSaving()
    Dim lNum As Long
  
    'SaveAttachmentsFromSelection(ByVal bDefaultPST As Boolean, ByVal strSourceFolder As String, ByVal streMailFolder, _
                                                ByVal rcvdDate As Date, ByVal strsubject As String, _
                                                ByVal bMoveEmail As Boolean, strDestPath As String, strMoveFolder As String) As Long
                                              
    'Function have 8 parametres
    '1. bDefaultPST - Is match conditions with default Inbox folder
    '2. strSourceFolder - If no 1 is false then pst file name
    '3. streMailFolder - If no 1 is false then folder from said pst
    '4. rcvdDate- Which Date
    '5. strsubject- Which subject - here i have seprated the subjected with "|" so that one can match multiple subjects
    'if only one subject have to match then write it as "subject1|" else "subject1|subject2"
    'you may add much as you can but seprated by "|"
    '6. bMoveEmail - Is move the email after attachemnt to another PST like as archive
    '7. strDestPath - if no 6 is true then which archive/pst
    '8. strMoveFolder - if no 6 is true then folder in archive/pst
  
  
    lNum = SaveAttachmentsFromSelection(False, "Email-Deepak", "Inbox", Date, "subject1|subject2", False, "Archive32", "Inbox")
  
    If Not bMsg Then
        If lNum > 0 Then
            MsgBox CStr(lNum) & " attachment(s) was(were) saved successfully.", vbInformation, "Message from Attachment Saver"
        Else
            MsgBox "No attachment(s) in the selected Outlook items.", vbInformation, "Message from Attachment Saver"
        End If
    End If
End Sub
 
Last edited:
Back
Top