Collating data from mails received in Outlook RRS feed

  • Question

  • I get about 14 mails on daily basis with same subject line expect the last word....example


    Daily Report India

    Daily Report Thailand

    Daily Report Srilanka

    All the mails are receieved in outlook and each mail has one xls attachement. I was a code where all these 14 mail attachement (14 xls) are extracted into one spread sheet.


    Kindly help!!

    Best Regards,

    Vinni Prasad

    Monday, June 9, 2014 7:50 AM


  • Hello Vinni,

    Are you going to develop a VBA macro or COM add-in?

    In both cases you need to handle the NewMailEx event of the Application class (fired when a new item is received in the Inbox) and extract the attached xls file. The Attachments property of the MailItem class from the Outlook object model returns an Attachments object that represents all the attachments for the specified item. So, you can find the required file (if any) and call the SaveAsFile method of the Attachment class which saves the attachment to the specified path. For example, the sample code listed below uses the SaveAsFile method to save the first attachment of the currently open item as a file in the Documents folder, using the attachment's display name as the
    file name.:

    Sub SaveAttachment()  
     Dim myInspector As Outlook.Inspector  
     Dim myItem As Outlook.MailItem  
     Dim myAttachments As Outlook.Attachments 
     Set myInspector = Application.ActiveInspector  
     If Not TypeName(myInspector) = "Nothing" Then  
     If TypeName(myInspector.CurrentItem) = "MailItem" Then  
     Set myItem = myInspector.CurrentItem  
     Set myAttachments = myItem.Attachments  
     'Prompt the user for confirmation  
     Dim strPrompt As String  
     strPrompt = "Are you sure you want to save the first attachment in the current item to the Documents folder? If a file with the same name already exists in the destination folder, it will be overwritten with this copy of the file."  
     If MsgBox(strPrompt, vbYesNo + vbQuestion) = vbYes Then  
     myAttachments.Item(1).SaveAsFile Environ("HOMEPATH") 
     "\My Documents\" & _  
     End If  
     MsgBox "The item is of the wrong type."  
     End If  
     End If  
    End Sub

    Monday, June 9, 2014 10:08 AM