跳到主要內容

如何將Outlook電子郵件正文文本導出到Excel電子表格?

如果要將選定的電子郵件正文文本從Outlook導出到Excel電子表格,則本文中的方法可以為您提供幫助。

使用VBA代碼將Outlook電子郵件正文文本導出到Excel電子表格


使用VBA代碼將Outlook電子郵件正文文本導出到Excel電子表格<

請運行下面的VBA代碼,將Outlook電子郵件的選定正文文本導出到Excel。

1.打開電子郵件,選擇要導出到Excel電子表格的電子郵件正文,然後按 其他 + F11 鍵打開 Microsoft Visual Basic for Applications 窗口。

2。 在裡面 Microsoft Visual Basic for Applications 窗口中,單擊 插入 > 模塊。 然後將下面的VBA代碼複製到“代碼”窗口中。

VBA代碼:將Outlook電子郵件正文文本導出到Excel電子表格

Sub ExportToExcel()
Dim xExcel As Excel.Application
Dim xWb As Workbook
Dim xWs As Worksheet
Dim xInspector As Inspector
Dim xItem As Object
Dim xMailItem As MailItem
Dim xDoc As Document
Dim xShell As Object
Dim xFilePath As String
On Error Resume Next
    Set xShell = CreateObject("Shell.Application")
    Set xFolder = xShell.BrowseForFolder(0, "Select a Folder:", 0, 0)
    If TypeName(xFolder) = "Nothing" Then Exit Sub
    Set xFolderItem = xFolder.Self
    xFilePath = xFolderItem.Path & "\"
    Set xItem = Outlook.Application.ActiveExplorer.Selection.item(1)
    If xItem.Class <> olMail Then Exit Sub
    Set xMailItem = xItem
    Set xInspector = xMailItem.GetInspector
    Set xDoc = xInspector.WordEditor
    xDoc.Application.Selection.Range.Copy
    xInspector.Close olDiscard
    Set xExcel = New Excel.Application
    Set xWb = xExcel.Workbooks.Add
    Set xWs = xWb.Sheets.item(1)
    xExcel.Visible = False
    xWs.Activate
    xWs.Paste
    xWs.SaveAs xFilePath & "Email body.xlsx"
    xWb.Close True
    xExcel.Quit
    Set xWs = Nothing
    Set xWb = Nothing
    Set xExcel = Nothing
End Sub

備註:在代碼中,“電子郵件body.xlsx”是您將使用所選電子郵件正文文本創建的工作簿名稱。 您可以根據需要進行更改。

3。 點擊 工具 > 參考。 然後檢查 Microsoft Excel對像庫Microsoft Word對像庫 中的框 參考–項目 對話框。 看截圖:

4.然後 瀏覽文件夾 彈出對話框,請選擇一個文件夾來保存工作簿,然後單擊 OK 按鈕。

現在,一個名為“電子郵件正文”將創建並保存到指定的文件夾中。 打開工作簿,您可以看到所選的電子郵件正文文本已導出到工作簿的Sheet1。


最佳辦公生產力工具

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

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

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

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

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

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

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

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

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

閱讀更多       免費下載      購買
 

 

Comments (4)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
this work but in one email only what if in folder theres a multiple email thats need to be extracted in excel?
This comment was minimized by the moderator on the site
Você vai precisar implementar o código fazendo um Looping, com um FOR por exemplo:

Sub lerEmails()

' Criando a aplicação do Outlook
Dim objOutlook As Object
Set objOutlook = CreateObject("Outlook.Application")

' Criando um Namespace, que seria uma sessão no Outlook
Dim objNSpace As Object
Set objNSpace = objOutlook.GetNamespace("MAPI")

' Cria um objeto com a pasta Inbox do Outlook
Dim minhaPasta As Object
Set minhaPasta = objNSpace.GetDefaultFolder(olFolderInbox)

Dim i As Long
Dim itemPasta As Object

i = 2 'Linha que vai começar preenchendo na planilha

' Percorrer todos os itens dentro da pasta
For Each itemPasta In minhaPasta.Items

If itemPasta.Class = olMail Then
Dim objEmail As Outlook.MailItem
Set objEmail = itemPasta

Cells(i, 1).Value = objEmail.SenderEmailAddress
Cells(i, 2).Value = objEmail.To
Cells(i, 3).Value = objEmail.Subject
Cells(i, 4).Value = objEmail.ReceivedTime
Cells(i, 5).Value = objEmail.Body
Cells(i, 5).WrapText = False

End If
i = i + 1

Next

Set objEmail = Nothing
Set objOutlook = Nothing
Set objNSpace = Nothing
Set minhaPasta = Nothing

End Sub
This comment was minimized by the moderator on the site
Hi the code only returned directly, into the excel and not the body of the email, may I know why was that??
This comment was minimized by the moderator on the site
same issue for me as well
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations