【问题标题】:Mass Export outlook letters with ConversationID带有 ConversationID 的批量出口前景信件
【发布时间】:2017-07-06 14:39:36
【问题描述】:

我需要将所有带有标准 Outlook 字段(发件人/收件人/主题/日期,包括类别,最重要的是 ConversationID)的电子邮件提取到 Excel/csv 中。 我使用的是 MS Office 2016,不知道 Exchange 服务器的版本。

我在邮箱上尝试了几种方法: 1)通过标准outlook界面导出数据 2) 通过标准导出主机将数据导出到 MS 访问 3) 直接从 MS Exchange 提取数据到 MS PowerBI

在所有 3 种情况下,我都无法获得 ConversationID(PowerBI 提取有一些 ID,但不是 ConversationID)

现在我知道它应该以某种方式通过 MAPI 提取,但我完全不了解这个主题。一些搜索建议为此使用特殊软件,例如 Transcend,但对于一个用户来说显然太贵了:)

我还发现 VBA 代码可以直接将数据导入 Excel,但它对我不起作用: http://www.tek-tips.com/viewthread.cfm?qid=1739523 还发现了这个很好的解释什么是 ConversationID - 可能对其他感兴趣的主题有帮助: https://www.meridiandiscovery.com/how-to/e-mail-conversation-index-metadata-computer-forensics/

【问题讨论】:

  • 在您现有的代码中究竟是什么不工作?
  • 在这部分执行时出现错误User-defined type not defined Public ns As Outlook.Namespace @DmitryStreblechenko
  • 这仅仅意味着您没有将 Outlook 添加到您的项目引用中。
  • b但是怎么做呢?
  • 你的代码在哪里运行?

标签: vba outlook exchange-server mapi


【解决方案1】:

这里有一些示例代码可以帮助您入门,我已经有了与您的问题类似的内容。代码已注释,但请随时提出问题:)

Option Explicit

Public Sub getEmails()
On Error GoTo errhand:

    'Create outlook objects and select a folder
    Dim outlook     As Object: Set outlook = CreateObject("Outlook.Application")
    Dim ns          As Object: Set ns = outlook.GetNameSpace("MAPI")

    'This option open a new window for you to select which folder you want to work with
    Dim olFolder    As Object: Set olFolder = ns.pickFolder
    Dim emailCount  As Long: emailCount = olFolder.Items.Count
    Dim i           As Long
    Dim myArray     As Variant
    Dim item        As Object

    ReDim myArray(4, (emailCount - 1))

    For i = 1 To emailCount
        Set item = olFolder.Items(i)
        '43 is olMailItem, only consider this type of email message
        'I'm assuming you only want items with a conversationID
        'Change the logic here to suite your specific needs
        If item.Class = 43 And item.ConversationID <> vbNullString Then
            'Using an array to write to excel in one go
            myArray(0, i - 1) = item.Subject
            myArray(1, i - 1) = item.SenderName
            myArray(2, i - 1) = item.To
            myArray(3, i - 1) = item.CreationTime
            myArray(4, i - 1) = item.ConversationID
        End If
    Next

    'Adding headers, then writing the data to excel
    With ActiveSheet
        .Range("A1") = "Subject"
        .Range("B1") = "From"
        .Range("C1") = "To"
        .Range("D1") = "Created"
        .Range("E1") = "ConversationID"
        .Range("A2:E" & (emailCount + 1)).Value = TransposeArray(myArray)
    End With

    Exit Sub

errhand:
    Debug.Print Err.Number, Err.Description
End Sub

'This function is used to bypass the limitation of -
'application.worksheetfunction.transpose
'If you have too much data added to an array you'll get a type mismatch
'Found here - http://bettersolutions.com/vba/arrays/transposing.htm
Public Function TransposeArray(myArray As Variant) As Variant
    Dim X           As Long
    Dim Y           As Long
    Dim Xupper      As Long: Xupper = UBound(myArray, 2)
    Dim Yupper      As Long: Yupper = UBound(myArray, 1)
    Dim tempArray   As Variant

    ReDim tempArray(Xupper, Yupper)

    For X = 0 To Xupper
        For Y = 0 To Yupper
            tempArray(X, Y) = myArray(Y, X)
        Next
    Next

    TransposeArray = tempArray
End Function

【讨论】:

  • 它有效,但 1) 仅适用于收件箱文件夹,当我尝试使用“已发送”或整个邮箱时它不起作用。 2)对话ID不完整(只有第一个“base”34个符号“。实际上那个convID适合我,但它没有显示完整的ConvID,只有“base”字符串。是否有可能得到完整-长度 convID?出于好奇而询问。
  • 我很高兴这是一个有效的例子。您可以对其进行调整以满足您的需求。请标记为已关闭
  • 完全为我工作。仍然 categoryID 没有完整的长度,但这对我的特定任务来说很好
  • 嘿瑞恩,我今天再次尝试了这段代码(每年都做一次),虽然发送文件夹提取得很好,但当我尝试在“收件箱”文件夹中使用它时,excel 冻结了一段时间然后没有任何反应(空工作表)。同样,它在 Sent 或 Drafts 文件夹上工作,但在 Inbox 上没有工作。我的假设是 Inbox 有太多的项目(即使我试图将本地副本站点的范围更改为 6 个月而不是 1 年,我确实收到了很多电子邮件最近)。有没有机会解决它?
  • 没有看到场景可能是电子邮件太多。使用Restrict 方法分解收件箱。见msdn.microsoft.com/en-us/vba/outlook-vba/articles/…
猜你喜欢
  • 1970-01-01
  • 2015-09-25
  • 2014-08-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-14
  • 2014-12-05
  • 2016-11-14
相关资源
最近更新 更多