如何快速將投票統計信息從Outlook電子郵件導出到Excel工作表

立即分享:

如果您發送了帶有投票按鈕的電子郵件,在收件人向您發送回復後,您可能需要計算投票統計數據並將其導出到 Excel 工作表。 所以,在這個 post,我們將教您如何快速實現。

Outlook 非常強大,它甚至提供了“投票”功能。 我之前的文章“熟練使用MS Outlook進行投票”教會瞭如何有效地利用它。 還有,米ost 有時,投票後,您可能會出於某些原因將投票統計數據導出到 Excel 工作表,例如希望將統計數據打印出來。 但默認情況下 Outlook 不支持此功能。 因此,在下面,我們將教您如何像軟木塞一樣實現這一點。

將 Outlook 電子郵件中的投票統計數據快速導出到 Excel 工作表

將電子郵件中的投票統計數據導出到 Excel 工作表

  1. 首先,啟動Outlook應用程序。
  2. 然後你應該在主 Outlook 窗口中按“Alt + F11”鍵按鈕。
  3. 接下來在“Microsoft Visual Basic for Applications”窗口中,您應該啟用“Microsoft Excel Object Library”。 單擊“工具”>“參考”。 然後在彈出的對話框中,勾選“Microsoft Excel Object Lib”前面的複選框rary”,最後點擊“OK”。
  4. 之後,您可以插入一個新模塊或打開一個未使用的模塊。
  5. 隨後,將以下VBA代碼複製並粘貼到該模塊中。
Sub ExportVotingStatistics _Excel ()
    Dim objMail As Outlook.MailItem
    Dim objRecipient As Outlook.recipient
    Dim objVoteDictionary As Object
    Dim varVotingCounts As Variant
    Dim varVotingOptions As Variant
    Dim varVotingOption As Variant
    Dim i As Long
    Dim objExcelApp As Excel.Application
    Dim objExcelWorkbook As Excel.Workbook
    Dim objExcelWorksheet As Excel.Worksheet
    Dim nRow As Integer
 
    Set objMail = Application.ActiveExplorer.Selection(1)
 
    'Create a new excel worksheet
    Set objExcelApp = CreateObject("Excel.Application")
    Set objExcelWorkbook = objExcelApp.Workbooks.Add
    Set objExcelWorksheet = objExcelWorkbook.Sheets(1)
 
    'Fill in the predefined values
    With objExcelWorksheet
         .Cells.Font.Name = "Cambria"
         .Cells(1, 1) = "Voting Results for Email:"
         .Cells(1, 2) = Chr(34) & objMail.Subject & Chr(34)
         .Cells(3, 1) = "Voting Options"
         .Cells(3, 2) = "Voting Counts"
    End With
 
    Set objVoteDictionary = CreateObject("Scripting.Dictionary")
    'get the default voting options
    varVotingOptions = Split(objMail.VotingOptions, ";")
    'Add the voting responses to the dictionary
    For Each varVotingOption In varVotingOptions
        objVoteDictionary.Add varVotingOption, 0
    Next
    'Add a custom voting response - "No Reply"
    objVoteDictionary.Add "No Reply", 0
 
    'Process the all voting responses
    For Each objRecipient In objMail.Recipients
        If objRecipient.TrackingStatus = olTrackingReplied Then
           If objVoteDictionary.Exists(objRecipient.AutoResponse) Then
              objVoteDictionary.Item(objRecipient.AutoResponse) = objVoteDictionary.Item(objRecipient.AutoResponse) + 1
           Else
              objVoteDictionary.Add objRecipient.AutoResponse, 1
           End If
        Else
           objVoteDictionary.Item("No Reply") = objVoteDictionary.Item("No Reply") + 1
        End If
    Next
 
    'Get the voting options and vote counts
    varVotingOptions = objVoteDictionary.Keys
    varVotingCounts = objVoteDictionary.Items
 
    'Fill in the values in specific cells
    nRow = 4
    For i = LBound(varVotingOptions) To UBound(varVotingOptions)
        With objExcelWorksheet
             .Cells(nRow, 1) = varVotingOptions(i)
             .Cells(nRow, 2) = varVotingCounts(i)
        End With
        nRow = nRow + 1
    Next
 
    'Save the new Excel file
    objExcelWorksheet.Columns("A:B").AutoFit
    strExcelFile = "E:\Voting Results " & Format(Now, "YYYY-MM-DD hh-mm-ss") & ".xlsx"
    objExcelWorkbook.Close True, strExcelFile

    MsgBox "Complete!", vbExclamation
End Sub

VBA 代碼 - 從 Outlook 電子郵件導出投票統計數據到 Excel 工作表

  1. 之後,為了方便訪問,您最好將新宏添加到快速訪問工具欄。
  2. 最終,您可以嘗試一下。
  • 首先,選擇包含投票按鈕的源電子郵件。
  • 然後單擊快速訪問工具欄中的宏按鈕。
  • 此宏運行完畢後,您可以瀏覽到預定義的本地文件夾,您將在其中看到一個新的 Excel 工作簿。
  • 打開此 Excel 工作簿。 現在您將看到投票統計信息,如下圖所示:導出投票統計

沒有人可以徹底避免 Outlook 錯誤

儘管 Outlook 具有多種功能,但沒有這樣的功能可以幫助我們避免 Outlook 錯誤。 各種因素都可能導致 Outlook 錯誤。 例如,如果您經常不正確地退出 Outlook,您可能會遭受 PST腐敗. 在這種情況下,您別無選擇,只能使用一些強大的工具來拯救您的 PST 文件,例如 DataNumen Outlook Repair. 由於回收率高,它贏得了很多讚譽。

作者簡介:

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

立即分享:

評論被關閉。