How to Quickly Extract the Email Addresses from the Tables in Your Outlook Email

If you need to extract all email addresses appearing in all tables of an email, you can use the method shown in this article. It can let you get it in a jiffy.

You receive an email, which contains a lot of email addresses in its message body. Some of the email addresses are in the tables, but some are in the textual body. At times, you may only want to extract the email addresses from the tables. Usually, in standard means, you have to manually copy to extract the email addresses. But, it will be quite cumbersome if there are too many tables in this email. Therefore, in the followings, we will share you an approach, which can let you get it in bulk.

Quickly Extract the Email Addresses from the Tables in Email

  1. At the very outset, launch Outlook application.
  2. Then, press “Alt + F11” to trigger VBA editor.
  3. Next, add reference to “MS Word Object Library” by reading “How to Add an Object Library Reference in VBA“.
  4. Then, copy the following code into an unused module.
Sub ExtractEmailAddressesFromAllTables()
    Dim objMail As Outlook.MailItem
    Dim objMailDocument As Word.Document
    Dim strEmailAddresses As String
    Dim objNewMail As Outlook.MailItem
    Dim objNewMailDocument As Word.Document
 
    'Get the mail
    Select Case Outlook.Application.ActiveWindow.Class
           Case olInspector
                Set objMail = ActiveInspector.CurrentItem
           Case olExplorer
                Set objMail = ActiveExplorer.Selection.Item(1)
    End Select
 
    Set objMailDocument = objMail.GetInspector.WordEditor
 
    'Find all email addresses via wildcards
    With objMailDocument.Range
         With .Find
              .ClearFormatting
              .Replacement.ClearFormatting
              .Text = "[A-z,0-9]{1,}\@[A-z,0-9,.]{1,}"
              .MatchWildcards = True
              .Forward = True
              .Wrap = wdFindStop
              .Execute
         End With
 
         'Get the email addresses in table
         Do Until .Find.Found = False
               If .Information(wdWithInTable) = True Then
                  strEmailAddresses = .Cells(1).Range.Text & strEmailAddresses
               End If
               .Collapse wdCollapseEnd
               .Find.Execute
         Loop
    End With
 
    'Input the extracted email addresses from all tables into a new mail
    Set objNewMail = Outlook.CreateItem(olMailItem)
    With objNewMail
         .Body = strEmailAddresses
         .Display
         With .GetInspector.WordEditor.Application.Selection
              .WholeStory
              .Range.Font.Size = 12
         End With
    End With
End Sub

VBA Code - Quickly Extract the Email Addresses from the Tables in Email

  1. Later exit the current window.
  2. Subsequently, follow the “Optional Step” in “How to Run VBA Code in Your Outlook” to add this macro to Quick Access Toolbar or ribbon.
  3. Finally, you can have a try.
  • First, select or open an email.
  • Then, run this macro by clicking the newly added button in Quick Access Toolbar or ribbon.Click Macro Button
  • At once, a new email will show up, which contains all the extracted email addresses in its message body, like the following screenshot.Extracted Email Address in New Mail

Recover from Outlook Crashes

From time to time, Outlook can crash unexpectedly. At the best, nothing bad will happen. A simple restart can restore it. However, at the worst, you will encounter serious Outlook corruption. At that time, you need to fix Outlook file. You can use the inbox repair tool to have a try. If it fails, then you can resort to a more potent external tool, such as 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 SQL Server recovery and outlook repair software products. For more information visit www.datanumen.com

Comments are closed.