Vba 将分类电子邮件的详细信息导出到Excel
我在网上找到了下面的脚本并试图修改。我想检查颜色类别,而不是标记的电子邮件 例如,它不会检查是否标记了电子邮件,然后将详细信息导出到excel,但会导出所有内容,并添加一个关于电子邮件标记的类别(名称)的第6列 以下是在Outlook中处理电子邮件的代码Vba 将分类电子邮件的详细信息导出到Excel,vba,outlook,Vba,Outlook,我在网上找到了下面的脚本并试图修改。我想检查颜色类别,而不是标记的电子邮件 例如,它不会检查是否标记了电子邮件,然后将详细信息导出到excel,但会导出所有内容,并添加一个关于电子邮件标记的类别(名称)的第6列 以下是在Outlook中处理电子邮件的代码 Sub ProcessMailFolders(ByVal objCurrentFolder As Outlook.Folder) Dim i As Long Dim objMail As Outlook.MailItem
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
子进程邮件文件夹(作为Outlook.Folder的ByVal objCurrentFolder)
我想我会坚持多久
将objMail设置为Outlook.MailItem
Dim objFlaggedMail作为Outlook.MailItem
Dim nLastRow作为整数
将objSubfolder设置为Outlook.Folder
对于i=1到objCurrentFolder.Items.Count
如果objCurrentFolder.Items(i).Class=olMail,则
'将每个标记电子邮件的信息导出到Excel
设置objMail=objCurrentFolder.Items(i)
如果objMail.IsMarkedAsTask=True且objMail.FlagStatus olflagscomplete,则
设置objFlaggedMail=objMail
使用objexcel工作表
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
以
如果结束
如果结束
接下来我
如果objCurrentFolder.Folders.Count>0,则
对于objCurrentFolder.Folders中的每个objSubfolder
调用ProcessMailFolders(objSubfolder)
下一个
如果结束
端接头
引用Excel的代码我可以修改,但不需要检查分类而不是标记的电子邮件。您需要更改“如果”语句。邮件项目有一个名为categories的属性,该属性返回字符串。 更改:
如果设置了多个类别,则“工作类别”属性会返回一个“;”分隔的类别列表。
If objMail.IsMarkedAsTask = True And objMail.FlagStatus <> olFlagComplete Then
If objMail.Categories = ***Insert Category Name In Quotes*** Then