简体   繁体   English

将电子邮件从 Outlook 2010 中的已发送文件夹复制到 Excel 文件

[英]Copy emails from my Sent Folder in Outlook 2010 to an Excel file

I need to make a record of some emails I've sent over the last couple years, and to include who they were sent to, the date, and the body of the message.我需要记录我在过去几年中发送的一些电子邮件,并包括他们的收件人、日期和邮件正文。 Exporting from Outlook does not carry the date, and for some reason Access won't import data from Outlook on my company computers从 Outlook 导出不带有日期,并且出于某种原因,Access 不会从我公司计算机上的 Outlook 导入数据

I came across this macro to export from Outlook to Excel, most of the information I need, but it pulls from the inbox: http://officetricks.com/outlook-email-download-to-excel/我遇到了这个从 Outlook 导出到 Excel 的宏,我需要的大部分信息,但它从收件箱中提取: http : //officetricks.com/outlook-email-download-to-excel/

I searched the Office VBA website for commands to make it export from the Sent Items folder instead of the Inbox, but I kept getting run-time error 438 "Object doesn't support this property or method" at the ReceivedByDate and CC lines (under the For command below).我找遍了办公室VBA网站的命令,使之从已发送邮件导出文件夹,而不是收件箱,但我一直得到运行时错误438“对象不支持此属性或方法”在ReceivedByDate和CC线(下下面的 For 命令)。 It only happens to my sent emails.它只发生在我发送的电子邮件上。 I tried moving them to a separate folder and into my Inbox, but the macro fails when it reads emails sent from me.我尝试将它们移动到一个单独的文件夹并放入我的收件箱,但宏在读取我发送的电子邮件时失败。

Sub Mail_to_Excel()
'
' Mail_to_Excel Macro
' Copies emails from Outlook to an Excel file
' Add Tools->References->"Microsoft Outlook nn.n Object Library"
' nn.n varies as per our Outlook Installation
    Dim Folder As Outlook.MAPIFolder
    Dim iRow As Integer, oRow As Integer
    Dim MailBoxName As String, Pst_Folder_Name  As String

    'Mailbox or PST Main Folder Name (As how it is displayed in your Outlook Session)
    MailBoxName = "MyName@Company.com"

    'Mailbox Folder or PST Folder Name (As how it is displayed in your Outlook Session)
    Pst_Folder_Name = "Sent Items"

    Set Folder = Outlook.Session.Folders(MailBoxName).Folders(Pst_Folder_Name)
    If Folder = "" Then
        MsgBox "Invalid Data in Input"
        GoTo end_lbl1:
    End If

    'Read Through each Mail and export the details to Excel for Email Archival
    ThisWorkbook.Sheets(1).Activate
    Folder.Items.Sort "Received"

    'Insert Column Headers
    ThisWorkbook.Sheets(1).Cells(1, 1) = "Sent to"
    ThisWorkbook.Sheets(1).Cells(1, 2) = "Copied"
    ThisWorkbook.Sheets(1).Cells(1, 3) = "Subject"
    ThisWorkbook.Sheets(1).Cells(1, 4) = "Date"
    ThisWorkbook.Sheets(1).Cells(1, 5) = "Size"
    ThisWorkbook.Sheets(1).Cells(1, 6) = "Body"

    'Insert Mail Data
    For iRow = 1 To 5
    'Folder.Items.Count
        oRow = iRow + 1
        ThisWorkbook.Sheets(1).Cells(oRow, 1).Select
        ThisWorkbook.Sheets(1).Cells(oRow, 1) = Folder.Items.Item(iRow).ReceivedByName
        ThisWorkbook.Sheets(1).Cells(oRow, 2) = Folder.Items.Item(iRow).CC
        ThisWorkbook.Sheets(1).Cells(oRow, 3) = Folder.Items.Item(iRow).Subject
        ThisWorkbook.Sheets(1).Cells(oRow, 4) = Folder.Items.Item(iRow).ReceivedTime
        ThisWorkbook.Sheets(1).Cells(oRow, 5) = Folder.Items.Item(iRow).Size
        ThisWorkbook.Sheets(1).Cells(iRow, 6) = Folder.Items.Item(iRow).Body
    Next iRow

    MsgBox "Outlook Mails Extracted to Excel"

end_lbl1:
End Sub

Try SentOn https://msdn.microsoft.com/en-us/library/office/ff864408.aspx instead of ReceivedTime.尝试 SentOn https://msdn.microsoft.com/en-us/library/office/ff864408.aspx而不是 ReceivedTime。

You may be interested in a discrepancy between the two.您可能对两者之间的差异感兴趣。 MAPI Outlook object model Mailitem.senton > Mailitem.receivedtime, how is this possible? MAPI Outlook 对象模型 Mailitem.senton > Mailitem.receivedtime,这怎么可能?

Some items in the Sent Items folder will not be mailitems so may not have a .CC property. Sent Items 文件夹中的某些项目不是邮件项目,因此可能没有 .CC 属性。

You will need a test like你需要一个像

If Item(iRow).class = olMail then

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM