提示:其它语言是由 Google 机器翻译的。 你可以访问 English 版本。
登录
x
or
x
x
马上登记
x

or

如何自动将Outlook中的电子邮件导出到Excel?

通常,您可以使用“导入/导出”功能将Outlook中的电子邮件导出到Excel。 但是,您是否曾尝试在新邮件到达时自动将电子邮件导出到Excel文件? 在本文中,我将讨论如何在Excel中自动导出新传入消息的信息。

使用VBA代码自动将Outlook中的电子邮件信息导出到Excel


将收件箱/已发送物品/草稿中的emials快速导出到Excel文件:

您订购的 Kutools for Outlook's 快速报告 功能,您可以轻松生成XML文件,以报告当前电子邮件文件夹或任务文件夹中的所有项目信息

doc自动导出电子邮件到excel 5

Kutools for Outlook:拥有超过40 +便利的Excel加载项,可以在60的日子里免费试用而没有限制。 立即下载并免费试用!

使用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 窗口,双击 ThisOutlookSession 来自 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


Kutools for Outlook - 为Outlook带来100高级功能,让工作更轻松!

  • 自动CC / BCC 发送电子邮件时的规则; 自动转发 多个电子邮件按自定义; 自动回复 没有交换服务器,以及更多自动功能......
  • BCC警告 - 当您尝试回复所有内容时显示消息 如果您的邮件地址在BCC列表中; 缺少附件时提醒,以及更多提醒功能......
  • 回复(全部)使用邮件会话中的所有附件; 回复很多电子邮件 很快; 自动添加问候语 回复时; 将日期添加到主题...
  • 附件工具:管理所有邮件中的所有附件, 自动分离, 全部压缩,重命名全部,全部保存...快速报告, 计算选定的邮件...
  • 强大的垃圾邮件 按惯例; 删除重复邮件和联系人... 使您能够在Outlook中更智能,更快速,更好地完成工作。
拍摄kutools outlook kutools选项卡1180x121
拍摄kutools outlook kutools加标签1180x121
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Sailu G · 1 months ago
    I have followed above steps but have blanks in excel.
    what should I do?
  • To post as a guest, your comment is unpublished.
    Marduk20 · 6 months ago
    How to capture the Categories, Importance or the User-defined column on the same folder view?
  • To post as a guest, your comment is unpublished.
    sagar khomane · 7 months ago
    Can you please let me know how to deal with sub-folders in above code.
  • To post as a guest, your comment is unpublished.
    Sagar · 7 months ago
    how to deal with subfolders.
  • To post as a guest, your comment is unpublished.
    Jorge · 1 years ago
    I need the help about exporting Email information sent (outgoing) emails
    • To post as a guest, your comment is unpublished.
      skyyang · 1 years ago
      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.