如何在Outlook中按狀態快速計數所有任務

立即分享:

任務可以具有五個狀態–“不是S”tarted”,“進行中”,“完成”,“等待他人”和“推遲”。 如果要按狀態快速計數所有任務,可以使用本文介紹的方法。

Outlook支持用戶將狀態分配給任務或標記的項目。 有五種狀態,分別是“ Not S”tarted”,“進行中”,“完成”,“等待他人”和“推遲”。 也許您的Outlook中有很多任務,並且它們處於不同的狀態。 現在,如果您想按狀態計數所有任務,則可以使用以下方式。任務狀態

快速按狀態統計所有任務

  1. 首先,通過參考“如何在Outlook中運行VBA代碼“。
  2. 然後,在VBA編輯器中,啟用對“ MS Excel對像庫”的引用rary”和“ MS Scripting Runtime”(根據“如何添加對像庫rary VBA中的參考“。
  3. 接下來,將以下代碼複製到未使用的模塊中。
Dim objDictionary As New Scripting.Dictionary

Sub CountTasksByStatus()
    Dim objStore As Outlook.Store
    Dim objOutlookFile As Outlook.Folder
    Dim objFolder As Outlook.Folder
    Dim objExcelApp As Excel.Application
    Dim objExcelWorkbook As Excel.Workbook
    Dim objExcelWorksheet As Excel.Worksheet
    Dim varStatuses As Variant
    Dim varTaskCounts As Variant
    Dim i As Integer
    Dim nLastRow As Integer
 
    'Count by Dictionary
    Set objDictionary = CreateObject("Scripting.Dictionary")
  
    'Process All Outlook data files
    For Each objStore In Application.Session.Stores
        Set objOutlookFile = objStore.GetRootFolder
        For Each objFolder In objOutlookFile.Folders
            If objFolder.DefaultItemType = olTaskItem Then
               Call ProcessTaskFolders(objFolder)
            End If
        Next
    Next
 
    'Export the counts to an Excel worksheet
    Set objExcelApp = CreateObject("Excel.Application")
    objExcelApp.Visible = True
    Set objExcelWorkbook = objExcelApp.Workbooks.Add
    Set objExcelWorksheet = objExcelWorkbook.Sheets(1)
 
    With objExcelWorksheet
        .Cells(1, 1) = "Status"
        .Cells(1, 1).Font.Bold = True
        .Cells(1, 2) = "Task Count"
        .Cells(1, 2).Font.Bold = True
    End With
 
    varStatuses = objDictionary.Keys
    varTaskCounts = objDictionary.Items
 
    For i = LBound(varStatuses) To UBound(varStatuses)
        nLastRow = objExcelWorksheet.Range("A" & objExcelWorksheet.Rows.Count).End(xlUp).Row + 1
        With objExcelWorksheet
            .Cells(nLastRow, 1) = varStatuses(i)
            .Cells(nLastRow, 2) = varTaskCounts(i)
        End With
    Next
 
    objExcelWorksheet.Columns("A:B").AutoFit
End Sub

Sub ProcessTaskFolders(ByVal objCurFolder As Outlook.Folder)
    Dim objTask As Outlook.TaskItem
    Dim strStatus As String
    Dim objSubfolder As Outlook.Folder
 
    'Count tasks by status
    For Each objTask In objCurFolder.Items
        Select Case objTask.Status
               Case olTaskNotStarted
                    strStatus = "Not Started"
 
                    If objDictionary.Exists(strStatus) Then
                       objDictionary(strStatus) = objDictionary(strStatus) + 1
                    Else
                       objDictionary.Add strStatus, 1
                    End If
               Case olTaskInProgress
                    strStatus = "In Progress"
 
                    If objDictionary.Exists(strStatus) Then
                       objDictionary(strStatus) = objDictionary(strStatus) + 1
                    Else
                       objDictionary.Add strStatus, 1
                    End If
               Case olTaskComplete
                    strStatus = "Completed"
 
                    If objDictionary.Exists(strStatus) Then
                       objDictionary(strStatus) = objDictionary(strStatus) + 1
                    Else
                       objDictionary.Add strStatus, 1
                    End If
               Case olTaskWaiting
                    strStatus = "Waiting on someone else"
 
                    If objDictionary.Exists(strStatus) Then
                       objDictionary(strStatus) = objDictionary(strStatus) + 1
                    Else
                       objDictionary.Add strStatus, 1
                    End If
               Case olTaskDeferred
                    strStatus = "Deferred"
 
                    If objDictionary.Exists(strStatus) Then
                       objDictionary(strStatus) = objDictionary(strStatus) + 1
                    Else
                       objDictionary.Add strStatus, 1
                    End If
         End Select
    Next
 
    'Process all subfolders recursively
    If objCurFolder.Folders.Count > 0 Then
       For Each objSubfolder In objCurFolder.Folders
           Call ProcessTaskFolders(objSubfolder)
       Next
    End If
End Sub

VBA代碼-按狀態計數任務

  1. 之後,單擊進入第一個子例程,然後按“ F5”鍵。
  2. 宏完成後,將立即顯示一個新的Excel工作表,如下面的屏幕截圖所示。 它包含處於不同狀態的任務計數。不同狀態的任務數

當心Outlook的陷阱

Outlook周圍存在大量風險,包括病毒,人為錯誤,軟件故障以及硬件故障等。因此,如果不想丟失寶貴的Outlook數據,則必須時刻保持謹慎。 簡而言之,您永遠不要下載電子郵件中的未知附件或可疑鏈接。 此外,如果可能,建議保留出色的Outlook修復實用程序,例如 DataNumen Outlook Repair,而不是完全依靠 收件箱維修工具.

作者簡介:

Shirley Zhang是的數據恢復專家 DataNumen,Inc.是數據恢復技術的全球領導者,包括 恢復SQL 和Outlook修復軟件產品。 欲了解更多信息,請訪問 萬維網。datanumen.COM

立即分享:

評論被關閉。