【发布时间】:2016-03-06 23:32:12
【问题描述】:
尝试使用来自另一个线程的 vba,但是,在“对于 flInbox.Items 中的每个 olMail”的行上获得了不匹配的类型。任何想法我做错了什么?我参考了outlook和excel。
Dim olMail As MailItem
Dim aOutput() As Variant
Dim lCnt As Long
Dim xlApp As Excel.Application
Dim xlSh As Excel.Worksheet
Dim flInbox As Folder
Set flInbox = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
ReDim aOutput(1 To flInbox.Items.Count, 1 To 4)
For Each olMail In flInbox.Items
If TypeName(olMail) = "MailItem" Then
lCnt = lCnt + 1
aOutput(lCnt, 1) = olMail.SenderEmailAddress 'maybe stats on domain
aOutput(lCnt, 2) = olMail.ReceivedTime 'stats on when received
aOutput(lCnt, 3) = olMail.ConversationTopic 'group based on subject w/o regard to prefix
aOutput(lCnt, 4) = olMail.Subject 'to split out prefix
End If
Next olMail
Set xlApp = New Excel.Application
Set xlSh = xlApp.Workbooks.Add.Sheets(1)
xlSh.Range("A1").Resize(UBound(aOutput, 1), UBound(aOutput, 2)).Value = aOutput
xlApp.Visible = True
链接:
Using VBA in Outlook to gather statistics on received emails
【问题讨论】:
-
您正在测试的文件夹可能不只包含邮件吗?也许还有其他文件夹?
-
嘿小鸟。不明白你的意思?它是我的正常收件箱,它没有子文件夹。只是收件箱、草稿、已发送邮件、已删除邮件。默认 Outlook 设置。