Skip to main content

How to export emails from Outlook to Excel automatically?

Normally, you can export the emails from Outlook to Excel with the Import/ Export feature. But, have you ever tried to auto export the emails to Excel file when new messages are arriving? In this article, I will talk about how to export the information of the new incoming messages automatically in Excel.

Auto export email information from outlook to Excel with VBA code

Export email information from outlook to Excel with an amazing feature


Auto export email information from outlook to Excel with VBA code

To export the new arriving emails to an Excel workbook automatically, please apply the following VBA code:

1. First, you should create a workbook with the below header information as following screenshot shown, so these information of the messages will be exported to this Excel file.

doc auto export emails to excel 1

2. Then go to Outlook and hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.

3. In the Microsoft Visual Basic for Applications window, double click ThisOutlookSession from the Project1(VbaProject.OTM) pane to open the mode, and then copy and paste the following code into the blank module.

VBA code: Auto export email information from Outlook to Excel file:

Public WithEvents GMailItems As Outlook.Items
Private Sub Application_Startup()
    Set GMailItems = Outlook.Application.Session.GetDefaultFolder(olFolderInbox).Items
End Sub
Private Sub GMailItems_ItemAdd(ByVal Item As Object)
    Dim xMailItem As Outlook.MailItem
    Dim xExcelFile As String
    Dim xExcelApp As Excel.Application
    Dim xWb As Excel.Workbook
    Dim xWs As Excel.Worksheet
    Dim xNextEmptyRow As Integer
    On Error Resume Next
    If Item.Class <> olMail Then Exit Sub
    Set xMailItem = Item
    xExcelFile = "C:\Users\DT168\Desktop\split document\kto-data.xlsx"
    If IsWorkBookOpen(xExcelFile) = True Then
        Set xExcelApp = GetObject(, "Excel.Application")
        Set xWb = GetObject(xExcelFile)
        If Not xWb Is Nothing Then xWb.Close True
    Else
        Set xExcelApp = New Excel.Application
    End If
    Set xWb = xExcelApp.Workbooks.Open(xExcelFile)
    Set xWs = xWb.Sheets(1)
    xNextEmptyRow = xWs.Range("B" & xWs.Rows.Count).End(xlUp).Row + 1
    With xWs
        .Cells(xNextEmptyRow, 1) = xNextEmptyRow - 1
        .Cells(xNextEmptyRow, 2) = xMailItem.SenderName
        .Cells(xNextEmptyRow, 3) = xMailItem.SenderEmailAddress
        .Cells(xNextEmptyRow, 4) = xMailItem.Subject
        .Cells(xNextEmptyRow, 5) = xMailItem.ReceivedTime
    End With
    xWs.Columns("A:E").AutoFit
    xWb.Save
End Sub
Function IsWorkBookOpen(FileName As String)
    Dim xFreeFile As Long, xErrNo As Long
    On Error Resume Next
    xFreeFile = FreeFile()
    Open FileName For Input Lock Read As #xFreeFile
    Close xFreeFile
    xErrNo = Err
    On Error GoTo 0
    Select Case xErrNo
        Case 0: IsWorkBookOpen = False
        Case 70: IsWorkBookOpen = True
        Case Else: Error xErrNo
    End Select
End Function

Note: In the above code, C:\Users\DT168\Desktop\split document\kto-data.xlsx is the Excel file path and Excel name that you want to locate the exported information, please change it to your need.

doc auto export emails to excel 2

4. Still in the Microsoft Visual Basic for Applications window, click Tools > References to go to the References-Project1 dialog box, and check Microsoft Excel Object Library option from the Available References list box, see screenshot:

doc auto export emails to excel 3

5. Then click OK button to close the dialog, and then save and close the code window.

6. Now, you should restart the Outlook to make this code take effect. From now on, if there are new emails arriving, they will be exported to the specific workbook automatically, see screenshot:

doc auto export emails to excel 4


Export email information from outlook to Excel with an amazing feature

If you want to export the emails from Inbox, Outbox or other folders to an Excel file, Kutools for Outlook's Quick Report can help you to easily generate an XML file for reporting all items’ information in current email folder or task folder as you need.

Note:To apply this Quick Report, firstly, you should download the Kutools for Outlook, and then apply the feature quickly and easily.

After installing Kutools for Outlook, please do as this:

1. Select a folder that you want to export all messages information, and then click Kutools Plus > Quick Report, see screenshot:

2. Then, in the popped out Save Report window, choose a location and specify a name for this exported file, see screenshot:

3. And then, click Save button to save this file, and in the popped out box, click Yes button to open the file, see screenshot:

4. Now, you can see all the information of the emails in the selected folder has been exported into the Excel file, see screenshot:


More relative articles:

  • Export Email Body Table To Excel In Outlook
  • When you receive an Email that contains some tables in the body, sometimes, you may need to export all tables from the message body to an excel worksheet. Normally, you can copy and paste the tables to worksheet, but, here, I will talk about a useful method to solve this job when there are multiple tables needed to be exported.
  • Extract Or Export Tasks List To Excel In Outlook
  • While using Outlook, you can extract the task list to Excel for other usage. With the powerful Export feature in Outlook, you can easily export your tasks list to Excel. Please do as below tutorial shows.
  • Export Contacts’ Information With Photos In Outlook
  • When you export contacts from Outlook to a file, only the text information of the contacts can be exported. But, sometimes, you need the photos to be exported as well as the contacts’ text information, how could you deal with this task in Outlook?

Best Office Productivity Tools

Kutools for Outlook - Over 100 Powerful Features to Supercharge Your Outlook

🤖 AI Mail Assistant: Instant pro emails with AI magic--one-click to genius replies, perfect tone, multilingual mastery. Transform emailing effortlessly! ...

📧 Email Automation: Out of Office (Available for POP and IMAP)  /  Schedule Send Emails  /  Auto CC/BCC by Rules When Sending Email  /  Auto Forward (Advanced Rules)   /  Auto Add Greeting   /  Automatically Split Multi-Recipient Emails into Individual Messages ...

📨 Email Management: Easily Recall Emails  /  Block Scam Emails by Subjects and Others  /  Delete Duplicate Emails  /  Advanced Search  /  Consolidate Folders ...

📁 Attachments ProBatch Save  /  Batch Detach  /  Batch Compress  /  Auto Save   /  Auto Detach  /  Auto Compress ...

🌟 Interface Magic: 😊More Pretty and Cool Emojis   /  Boost Your Outlook Productivity with Tabbed Views  /  Minimize Outlook Instead of Closing ...

👍 One-click Wonders: Reply All with Incoming Attachments  /   Anti-Phishing Emails  /  🕘Show Sender's Time Zone ...

👩🏼‍🤝‍👩🏻 Contacts & Calendar: Batch Add Contacts From Selected Emails  /  Split a Contact Group to Individual Groups  /  Remove Birthday Reminders ...

Over 100 Features Await Your Exploration! Click Here to Discover More.

Read More       Free Download      Purchase
 

 

Comments (8)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
If I have more than one email accounts in outlook, how can I output the emails from a specified account ?
This comment was minimized by the moderator on the site
I have followed above steps but have blanks in excel.
what should I do?
This comment was minimized by the moderator on the site
Same excel not getting updated? Any suggestions?
This comment was minimized by the moderator on the site
How to capture the Categories, Importance or the User-defined column on the same folder view?
This comment was minimized by the moderator on the site
Can you please let me know how to deal with sub-folders in above code.
This comment was minimized by the moderator on the site
how to deal with subfolders.
This comment was minimized by the moderator on the site
I need the help about exporting Email information sent (outgoing) emails
This comment was minimized by the moderator on the site
Hello, Jorge,
If you want to export the sent messages from the Sent Items folder, the Kutools for Outlook's Quick Report feature can help you. You can download the Kutools for Outlook first and then apply it.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations