将分类电子邮件的详细信息导出到Excel

问题描述 投票:0回答:1

我在网上找到了以下脚本,并尝试进行修改。我想检查颜色类别而不是已标记的电子邮件。

因此,它不会检查是否标记了电子邮件,然后将详细信息导出到excel,但会导出所有内容并添加关于电子邮件标记的类别(名称)的第6列。

这里是在Outlook中处理电子邮件的代码

Sub ProcessMailFolders(ByVal objCurrentFolder As Outlook.Folder)
    Dim i As Long
    Dim objMail As Outlook.MailItem
    Dim objFlaggedMail As Outlook.MailItem
    Dim nLastRow As Integer
    Dim objSubfolder As Outlook.Folder

    For i = 1 To objCurrentFolder.Items.Count
        If objCurrentFolder.Items(i).Class = olMail Then
            'Export the information of each flagged email to Excel
            Set objMail = objCurrentFolder.Items(i)
            If objMail.IsMarkedAsTask = True And objMail.FlagStatus <> olFlagComplete Then
                Set objFlaggedMail = objMail

                With objExcelWorksheet
                    nLastRow = .Range("A" & .Rows.Count).End(xlUp).Row + 1
                    .Range("A" & nLastRow) = objFlaggedMail.Subject
                    .Range("B" & nLastRow) = objFlaggedMail.TaskStartDate
                    .Range("C" & nLastRow) = objFlaggedMail.TaskDueDate
                    .Range("D" & nLastRow) = objFlaggedMail.SenderName
                    .Range("E" & nLastRow) = objFlaggedMail.To
                End With
            End If
        End If
    Next i

    If objCurrentFolder.Folders.Count > 0 Then
        For Each objSubfolder In objCurrentFolder.Folders
            Call ProcessMailFolders(objSubfolder)
        Next
    End If
End Sub

引用Excel的代码我可以修改,但是不能检查分类而不是标记的电子邮件。

vba outlook
1个回答
1
投票

您需要更改'if'语句。邮件项目具有称为类别的属性,该属性返回字符串。更改:

If objMail.IsMarkedAsTask = True And objMail.FlagStatus <> olFlagComplete Then

收件人:

If objMail.Categories = ***Insert Category Name In Quotes*** Then
© www.soinside.com 2019 - 2024. All rights reserved.