跳到主要內容

如何將電子郵件從Outlook自動導出到Excel?

通常,您可以使用導入/導出功能將電子郵件從Outlook導出到Excel。 但是,您是否曾經嘗試在收到新郵件時將電子郵件自動導出到Excel文件? 在本文中,我將討論如何在Excel中自動導出新傳入消息的信息。

使用VBA代碼自動將電子郵件信息從Outlook導出到Excel

借助出色功能將電子郵件信息從Outlook導出到Excel


使用VBA代碼自動將電子郵件信息從Outlook導出到Excel

要將新收到的電子郵件自動導出到Excel工作簿,請應用以下VBA代碼:

1。 首先,您應該使用下面的標題信息創建一個工作簿,如下面的屏幕快照所示,這樣消息的這些信息將被導出到此Excel文件中。

doc自動將電子郵件導出到excel 1

2。 然後轉到Outlook並按住 ALT + F11 鍵打開 Microsoft Visual Basic for Applications 窗口。

3。 在 Microsoft Visual Basic for Applications 窗口,雙擊 本次展望會議 來自 Project1(VbaProject.OTM) 窗格以打開模式,然後將以下代碼複製並粘貼到空白模塊中。

VBA代碼:自動將電子郵件信息從Outlook導出到Excel文件:

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

備註:在上面的代碼中, C:\ Users \ DT168 \ Desktop \ split document \ kto-data.xlsx 是您要查找導出信息的Excel文件路徑和Excel名稱,請根據需要進行更改。

doc自動將電子郵件導出到excel 2

4。 仍在 Microsoft Visual Basic for Applications 窗口中,單擊 工具 > 參考參考-Project1 對話框,然後檢查 Microsoft Excel對像庫 選項從 可用參考 列錶框,請參見屏幕截圖:

doc自動將電子郵件導出到excel 3

5。 然後點擊 OK 按鈕關閉對話框,然後保存並關閉代碼窗口。

6。 現在,您應該重新啟動Outlook,以使此代碼生效。 從現在開始,如果有新郵件到達,它們將自動導出到特定的工作簿中,請參見屏幕截圖:

doc自動將電子郵件導出到excel 4


借助出色功能將電子郵件信息從Outlook導出到Excel

如果要將電子郵件從“收件箱”,“發件箱”或其他文件夾導出到Excel文件, Kutools for Outlook's 快速報告 可以幫助您輕鬆生成XML文件,以便根據需要報告當前電子郵件文件夾或任務文件夾中所有項目的信息。

注意:要應用此 快速報告,首先,您應該下載 Kutools for Outlook,然後快速輕鬆地應用該功能。

安裝後 Kutools for Outlook,請這樣做:

1。 選擇您要導出所有郵件信息的文件夾,然後單擊“確定”。 Kutools 加 > 快速報告,請參見屏幕截圖:

2。 然後,在彈出 保存報告 窗口中,選擇一個位置並為此導出文件指定名稱,請參見屏幕截圖:

3。 然後,單擊 節省 按鈕以保存此文件,然後在彈出的框中單擊 按鈕打開文件,請參見屏幕截圖:

4。 現在,您可以看到所選文件夾中電子郵件的所有信息已導出到Excel文件中,請參見屏幕截圖:


更多相關文章:

  • 在Outlook中將電子郵件正文表導出到Excel
  • 當您收到一封包含正文中某些表的電子郵件時,有時,您可能需要將所有表從郵件正文導出到excel工作表中。 通常,您可以將表複製並粘貼到工作表中,但是,在這裡,我將討論一種有用的方法,當需要導出多個表時,可以解決此工作。
  • 將任務列表提取或導出到Outlook中的Excel
  • 使用Outlook時,可以將任務列表提取到Excel以供其他使用。 借助Outlook中強大的導出功能,您可以輕鬆地將任務列表導出到Excel。 請按照以下教程顯示進行操作。
  • 在Outlook中使用照片導出聯繫人信息
  • 當您將聯繫人從Outlook導出到文件時,只能導出聯繫人的文本信息。 但是,有時候,您需要導出照片以及聯繫人的文本信息,如何在Outlook中處理此任務?

最佳辦公生產力工具

Kutools for Outlook - 超過 100 種強大的功能可增強您的 Outlook

🤖 人工智慧郵件助手: 具備人工智慧魔力的即時專業電子郵件——一鍵天才回覆、完美語調、多語言掌握。輕鬆改變電子郵件! ……

📧 電子郵件自動化: 外出(適用於 POP 和 IMAP)  /  安排發送電子郵件  /  發送電子郵件時按規則自動抄送/密件副本  /  自動轉送(進階規則)   /  自動添加問候語   /  自動將多收件者電子郵件拆分為單獨的訊息 ...

📨 電子郵件管理: 輕鬆回憶電子郵件  /  按主題和其他人阻止詐騙電子郵件  /  刪除重複的電子郵件  /  進階搜索  /  合併資料夾 ...

📁 附件專業版批量保存  /  批量分離  /  批量壓縮  /  自動保存   /  自動分離  /  自動壓縮 ...

🌟 介面魔法: 😊更多又漂亮又酷的表情符號   /  使用選項卡式視圖提高 Outlook 工作效率  /  最小化 Outlook 而不是關閉 ...

👍 一鍵奇蹟: 使用傳入附件回覆全部  /   反網路釣魚電子郵件  /  🕘顯示寄件者的時區 ...

👩🏼‍🤝‍👩🏻 通訊錄和行事曆: 從選定的電子郵件中大量新增聯絡人  /  將聯絡人群組拆分為各組  /  刪除生日提醒 ...

超過 100特點 等待您的探索! 按此處了解更多。

了解更多       免費下載      購買
 

 

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