使用Excel VBA在第二级Outlook子文件夹中列出电子邮件

时间:2019-01-16 17:45:14

标签: excel vba outlook

我有四个邮箱ABC @ 123.com,DEF @ 123.com,GHI @ 123.com和JKL@123.com。

下面的代码转到我的名为refTables的选项卡中,以获取邮箱列表。仅转到那些收件箱。

我也想从所有子文件夹中获取电子邮件。

示例子文件夹名称:“正在进行中”,“待答复”和“已提交工单”。

Private Function getEmails(emailAddress, folderName, destinationSheet)

'retrieves emails form outlook given address, folder, and destination sheet

Row = 2
For Each Folder In Outlook.Session.Folders
    If Folder.Name = emailAddress Then
        For Each subfolder In Folder.Folders
            If subfolder.Name = folderName Then
                For Each Item In subfolder.Items
                    If TypeName(Item) = "MailItem" And Item.MessageClass <> "IPM.Outlook.Recall" Then
                        Sheets(destinationSheet).Cells(Row, 1) = Item.ReceivedTime
                        Sheets(destinationSheet).Cells(Row, 2) = Round(Now() - Item.ReceivedTime, 0)
                        Sheets(destinationSheet).Cells(Row, 3) = Item.Categories
                        Sheets(destinationSheet).Cells(Row, 4) = Item.SenderName
                        Sheets(destinationSheet).Cells(Row, 5) = Item.Subject
                        Sheets(destinationSheet).Cells(Row, 6) = Item.TaskCompletedDate
                        Sheets(destinationSheet).Cells(Row, 7) = Folder.Name
                        Sheets(destinationSheet).Cells(Row, 8) = Item.LastModificationTime
                        Sheets(destinationSheet).Cells(Row, 9) = Round(Item.TaskCompletedDate - Item.ReceivedTime)
                         Row = Row + 1
                    End If
                Next
            End If
        Next
    End If
Next

End Function

0 个答案:

没有答案