How to Quickly Count the Occurrences of a Specific Text in Multiple Outlook Emails

If you want to count how many times a specific text appears in multiple Outlook emails, you can refer to this article. It will share you a really rapid method, which is using VBA.

Some users ask for a quick solution to count the occurrences of a specific text in several Outlook emails. Undoubtedly, counting manually and one by one is quite tedious and troublesome. Thus, here we will expose a much more intelligent way. Now read on to get it in detail.

Quickly Count the Occurrences of a Specific Text in Multiple Outlook Emails

Count the Occurrences of a Specific Text in Multiple Emails

  1. For a start, launch your Outlook application as usual.
  2. Then, in the main Outlook window, shift to “Developer” tab and click on the “Visual Basic” button.
  3. After that, you will access the VBA editor in success. Now, you need to open a blank module, namely the one that is not in use.
  4. Next, you need to enable “Microsoft VBScript Regular Expressions”.
  • Click the “Tools” button in the toolbar.
  • Then choose “References” from the drop down list.
  • In the popup dialog box, you could scroll down until find and enable it.Enable “Microsoft VBScript Regular Expressions”
  1. Subsequently, you could copy and paste the following VBA code into it.
Sub CountOccurences_SpecificText_InEmails()
    Dim objSelection As Outlook.Selection
    Dim objMail As Outlook.MailItem
    Dim strSpecificText As String
    Dim objRegExp As RegExp
    Dim objMatches As MatchCollection
    Dim objMatch As match
    Dim lTextCount As Long
 
    Set objSelection = Application.ActiveExplorer.Selection
 
    If Not (objSelection Is Nothing) Then
       On Error Resume Next
 
       Set objRegExp = New RegExp
 
       strSpecificText = InputBox("Text to find:")
 
       lTextCount = 0
       For Each objMail In objSelection
           With objRegExp
                .IgnoreCase = False
                .Global = True
                .Pattern = strSpecificText
           End With
 
           Set objMatches = objRegExp.Execute(objMail.Body)
 
           If objMatches.count > 0 Then
              lTextCount = lTextCount + objMatches.count
           End If
       Next
 
       MsgBox lTextCount & " occurences of " & Chr(34) & strSpecificText & Chr(34) & " found in " & objSelection.count & " emails.", vbInformation
    End If
End Sub

VBA Code - Count the Occurrences of a Specific Text in Multiple Outlook Emails

  1. Later, you could exit the current window by hitting the “X” icon in the upper right corner.
  2. Then, you ought to go to “Outlook Options” to add this macro to Quick Access Toolbar.
  3. Finally you can have a try.
  • First off, in the email list, you can select one or more emails.
  • Then, click on the macro button in Quick Access Toolbar.
  • At this point, you will be required to input the specific text to find.Input Text to Find
  • After inputting and hit “OK”, you will get a message that shows the count of the occurrence of specific text in selected emails, like the image below:Message Prompting Count

Never Leave Outlook Issues Aside

It is inevitable that you will encounter myriad issues in your Outlook. In common cases, Outlook actually can recover simply via a restart. However, in the event of serious crash, what can you do? You shouldn’t leave the issues aside. Instead, you have to solve them as soon as possible, no matter via the inbuilt fix tool – Scanpst or an external experienced tool, like DataNumen Outlook Repair.

Author Introduction:

Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including mdf fix and outlook repair software products. For more information visit www.datanumen.com

Comments are closed.