VBA统计Outlook类别

时间:2012-10-15 14:09:20

标签: vba outlook

我是一名PHP程序员,对VBA来说是全新的......

在outlook中,我想要一个简单的提示,显示如下内容:

Red Category: 5 Emails
Blue Category: 7 Emails
Yellow Category: 8 Emails

我从微软那里得到了这个:

Sub ListCategoryColors()
 Dim objNameSpace As NameSpace
 Dim objCategory As Category
 Dim strOutput As String

 ' Obtain a NameSpace object reference.
 Set objNameSpace = Application.GetNamespace("MAPI")

 ' Check if the Categories collection for the Namespace
 ' contains one or more Category objects.
 If objNameSpace.Categories.Count > 0 Then

 ' Enumerate the Categories collection, checking
 ' the value of the Color property for
 ' each Category object.
 For Each objCategory In objNameSpace.Categories

 ' Add the name of the Category object to
 ' the output string.
 strOutput = strOutput & objCategory.Name

 ' Add information about the assigned color
 ' to the output string.
 Select Case objCategory.Color
 Case OlCategoryColor.olCategoryColorNone
 strOutput = strOutput & ": No color" & vbCrLf
 Case OlCategoryColor.olCategoryColorBlack
 strOutput = strOutput & ": Black " & vbCrLf
 Case OlCategoryColor.olCategoryColorBlue
 strOutput = strOutput & ": Blue" & vbCrLf
 Case OlCategoryColor.olCategoryColorGray
 strOutput = strOutput & ": Gray" & vbCrLf
 Case OlCategoryColor.olCategoryColorGreen
 strOutput = strOutput & ": Green" & vbCrLf
 Case OlCategoryColor.olCategoryColorMaroon
 strOutput = strOutput & ": Maroon" & vbCrLf
 Case OlCategoryColor.olCategoryColorOlive
 strOutput = strOutput & ": Olive" & vbCrLf
 Case OlCategoryColor.olCategoryColorOrange
 strOutput = strOutput & ": Orange" & vbCrLf
 Case OlCategoryColor.olCategoryColorPeach
 strOutput = strOutput & ": Peach" & vbCrLf
 Case OlCategoryColor.olCategoryColorPurple
 strOutput = strOutput & ": Purple" & vbCrLf
 Case OlCategoryColor.olCategoryColorRed
 strOutput = strOutput & ": Red" & vbCrLf
 Case OlCategoryColor.olCategoryColorSteel
 strOutput = strOutput & ": Steel" & vbCrLf
 Case OlCategoryColor.olCategoryColorTeal
 strOutput = strOutput & ": Teal" & vbCrLf
 Case OlCategoryColor.olCategoryColorYellow
 strOutput = strOutput & ": Yellow" & vbCrLf
 Case Else
 strOutput = strOutput & ": Unknown" & vbCrLf
 End Select
 Next
 End If

 ' Display the output string.
 MsgBox strOutput

 ' Clean up.
 Set objCategory = Nothing
 Set objNameSpace = Nothing

End Sub

但它只列出了类别及其名称。有人可以帮忙吗?感谢。

1 个答案:

答案 0 :(得分:0)

发现如果没有VB,这很容易实现。

输入

Category="red"

进入搜索栏,显示所有红色分类的电子邮件。然后,此类别中的总电子邮件将显示在状态栏中。