如果您想快速获取 Outlook PST 文件中每个颜色类别的项目总数,您可以使用本文中公开的 VBA 代码。 它会将所有计数直接导出到 Excel 文件中,方便您查看。
有时,出于某些原因,您可能想要计算 Outlook 数据文件中每个颜色类别中的项目数。 通常,您可以使用即时搜索来进行计数。 例如,首先点击进入搜索框。 然后单击“搜索”功能区中的“分类”按钮,然后从下拉列表中选择特定的颜色类别。 接下来在“范围”功能区组中选择“所有 Outlook 项目”。 稍后,搜索完成后,将列出所选颜色类别中的所有项目。 现在您可以在状态栏的左下角看到这些搜索结果的数量。
毫无疑问,如果你有很多颜色类别,通过这种方式,一个一个地计算会非常繁琐。 因此,针对这一需求,我们在此揭晓一个更为快捷的方法。 它会直接将所有计数导出到 Excel 文件中。
将 Outlook 中每个颜色类别中的项目计数导出到 Excel
- 首先,start 您的 Outlook 应用程序。
- 然后按“Alt + F11”键按钮访问 Outlook VBA 编辑器。
- 在随后出现的“Microsoft Visual Basic for Applications”窗口中,打开一个空白模块。
- 接下来,您可以将以下 VBA 代码复制到此模块窗口中。
Public objDictionary As Object
Public objExcelApp As Excel.Application
Public objExcelWorkbook As Excel.Workbook
Public objExcelWorksheet As Excel.Worksheet
Sub ExportCountofItemsinEachColorCategories()
Dim objCategories As Object
Dim objCategory As Object
Dim objPSTFile As Outlook.Folder
Dim objFolder As Outlook.Folder
Dim strExcelFile As String
'Create a New Excel file
Set objExcelApp = CreateObject("Excel.Application")
Set objExcelWorkbook = objExcelApp.Workbooks.Add
Set objExcelWorksheet = objExcelWorkbook.Sheets("Sheet1")
objExcelWorksheet.Cells(1, 1) = "Color Category"
objExcelWorksheet.Cells(1, 2) = "Count"
'Find all the color categories
Set objDictionary = CreateObject("Scripting.Dictionary")
Set objCategories = Outlook.Application.Session.Categories
For Each objCategory In objCategories
objDictionary.Add objCategory.Name, 0
Next
Set objPSTFile = Outlook.Application.Session.PickFolder
For Each objFolder In objPSTFile.Folders
ProcessFolder objFolder
Next
'Save the new Excel file
objExcelWorksheet.Columns("A:B").AutoFit
strExcelFile = "E:\Outlook\Color Categories (" & Format(Now, "yyyy-mm-dd_hh-mm-ss") & ").xlsx"
objExcelWorkbook.Close True, strExcelFile
MsgBox "Complete!", vbExclamation
End Sub
Private Sub ProcessFolder(ByVal objCurrentFolder As Outlook.Folder)
Dim objItem As Object
Dim objSubFolder As Object
Dim ArrayCategories As Variant
Dim VarCategory As Variant
Dim ArrayKey As Variant
Dim ArrayItem As Variant
Dim i As Long
Dim nRow As Integer
'Count the items in each color category via Dictionary object
For Each objItem In objCurrentFolder.Items
If objItem.Categories <> "" Then
ArrayCategories = Split(objItem.Categories, ",")
For Each VarCategory In ArrayCategories
If objDictionary.Exists(VarCategory) = True Then
objDictionary.Item(VarCategory) = objDictionary.Item(VarCategory) + 1
End If
Next
End If
Next
ArrayKey = objDictionary.Keys
ArrayItem = objDictionary.Items
nRow = 2
'Input the information into the new Excel file
For i = LBound(ArrayKey) To UBound(ArrayKey)
objExcelWorksheet.Cells(nRow, 1) = ArrayKey(i)
objExcelWorksheet.Cells(nRow, 2) = ArrayItem(i) & “ Items”
nRow = nRow + 1
Next
'Process the subfolders recursively
For Each objSubFolder In objCurrentFolder.Folders
ProcessFolder objSubFolder
Next
End Sub
- 之后,检查 Outlook 是否允许宏。
- 最后你可以试试看。
- 首先,在这个新宏中按 F5 键按钮。
- 然后您需要选择一个源 PST 文件并点击“确定”。
- 当您收到提示“完成”的消息时,您可以进入本地驱动器并打开预定义的用于保存Excel文件的文件夹。
- 找到并打开 Excel 文件。 它将如下图所示:
如果 Outlook 突然崩溃怎么办
尽管 Outlook 具有多种强大的功能,但随着时间的推移,您会在 Outlook 中遇到各种问题。 例如,Outlook 有时会崩溃。 充其量,restarting Outlook 将能够解决该问题。 在最坏的情况下,它会直接导致 PST 数据损坏。 届时,您将通过各种方式 修复PST 文件以取回最大的 Outlook 数据,为此您可以使用经验丰富的工具,例如 DataNumen Outlook Repair.
作者简介:
Shirley Zhang 是一位数据恢复专家 DataNumen, Inc.,它是数据恢复技术领域的世界领先者,包括 sql修复 和 outlook 修复软件产品。 欲了解更多信息,请访问 datanumen.com

