none
Export incoming and outgoing emails automatically to csv file RRS feed

  • Question

  • Hi, I was wondering if anyone knows how i can have outlook 2016 automatically export/link all incoming and outgoing emails to a csv file using VBA code 
    Tuesday, April 5, 2016 5:32 PM

Answers

  • Hello,

    First of all, I'd suggest starting from the Getting Started with VBA in Outlook 2010 article in MSDN.

    To process all incoming emails you need to handle the NewMailEx event of the Application class. The ItemSend event of the Application class allows to handle all outgoing emails. It is fired whenever an Microsoft Outlook item is sent, either by the user through an Inspector (before the inspector is closed, but after the user clicks the Send button) or when the Send method for an Outlook item, such as MailItem, is used in a program.


    [custom.development]

    • Proposed as answer by David_JunFeng Friday, April 15, 2016 2:09 PM
    • Marked as answer by David_JunFeng Monday, April 18, 2016 2:39 PM
    Tuesday, April 5, 2016 5:44 PM
  • Hi, Korkie123

    I think you could follow Eugene's suggestion. In addition you could write some information into CSV file like below:
    Sub DemoWriteCSVFile()
    
       'You must set a reference to the Microsoft Scripting Runtime library touse the FileSystemObject
    
       Dim objFS As Scripting.FileSystemObject
       Dim objOutputFile As Scripting.TextStream
    
       Set objFS = New Scripting.FileSystemObject
       Set objOutputFile = objFS.OpenTextFile("D:\Export.csv", ForWriting, True)
    
       'Write header line
        objOutputFile.WriteLine "From,Subject,Recived"
        
    '    ......
        
        objOutputFile.Close
        
    End Sub

    • Proposed as answer by David_JunFeng Friday, April 15, 2016 2:09 PM
    • Marked as answer by David_JunFeng Sunday, April 17, 2016 2:22 PM
    Wednesday, April 6, 2016 9:50 AM

All replies

  • Hello,

    First of all, I'd suggest starting from the Getting Started with VBA in Outlook 2010 article in MSDN.

    To process all incoming emails you need to handle the NewMailEx event of the Application class. The ItemSend event of the Application class allows to handle all outgoing emails. It is fired whenever an Microsoft Outlook item is sent, either by the user through an Inspector (before the inspector is closed, but after the user clicks the Send button) or when the Send method for an Outlook item, such as MailItem, is used in a program.


    [custom.development]

    • Proposed as answer by David_JunFeng Friday, April 15, 2016 2:09 PM
    • Marked as answer by David_JunFeng Monday, April 18, 2016 2:39 PM
    Tuesday, April 5, 2016 5:44 PM
  • Hi, Korkie123

    I think you could follow Eugene's suggestion. In addition you could write some information into CSV file like below:
    Sub DemoWriteCSVFile()
    
       'You must set a reference to the Microsoft Scripting Runtime library touse the FileSystemObject
    
       Dim objFS As Scripting.FileSystemObject
       Dim objOutputFile As Scripting.TextStream
    
       Set objFS = New Scripting.FileSystemObject
       Set objOutputFile = objFS.OpenTextFile("D:\Export.csv", ForWriting, True)
    
       'Write header line
        objOutputFile.WriteLine "From,Subject,Recived"
        
    '    ......
        
        objOutputFile.Close
        
    End Sub

    • Proposed as answer by David_JunFeng Friday, April 15, 2016 2:09 PM
    • Marked as answer by David_JunFeng Sunday, April 17, 2016 2:22 PM
    Wednesday, April 6, 2016 9:50 AM