How to Quickly Create an Outlook Contact Group from All Email Addresses Occurring in a Word Document

This article will guide you how to quickly extract all email addresses from a Word document and then create an Outlook contact group from them.

From my previous article “How to Quickly Create Outlook Contacts for All Email Addresses Occurring in a Word document”, you can learn to create corresponding Outlook contacts for all email addresses in a Word document like a cork. Similarly, some users would like to create a contact group from all these email addresses. Hence, here we will share another piece of VBA code, which can realize it within seconds.

Quickly Create an Outlook Contact Group from All Email Addresses Occurring in a Word Document

Create an Outlook Contact Group from All Email Addresses Occurring in a Word Document

  1. For a start, launch your Outlook program.
  2. Then in the main Outlook window, press “Alt + F11” keys.
  3. Next you will get into the Outlook VBA editor, in which you ought to access an empty module.
  4. Subsequently, copy the following VBA code into this module window.
Sub CreateContactGroup_fromAllEmailAddresses_inWordDocument()
    Dim objWordApp As Word.Application
    Dim objWordDocument As Word.Document
    Dim strEmailAddress As String
    Dim objMail As Outlook.MailItem
    Dim objContactGroup As Outlook.DistListItem
  
    Set objWordApp = CreateObject("Word.Application")
    objWordApp.Visible = True
    'Change the path to the specific Word document
    Set objWordDocument = objWordApp.Documents.Open("E:\Outlook\DataNumen Outlook Repair.docx")
 
    'Find the email addresses via wildcards
    With objWordApp.Selection.Find
         .Text = "[A-z,0-9]{1,}\@[A-z,0-9,.]{1,}"
         .MatchWildcards = True
         .Execute
    End With
 
    Set objMail = Application.CreateItem(olMailItem)
 
    While objWordApp.Selection.Find.Found
          'Get the email address
          strEmailAddress = objWordApp.Selection.Text
 
          objMail.Recipients.Add (strEmailAddress)
          objWordApp.Selection.Find.Execute
    Wend
 
    'Create a contact group
    Set objContactGroup = Application.CreateItem(olDistributionListItem)
 
    With objContactGroup
        .DLName = InputBox("Specify a name for the new contact group:")
        .AddMembers objMail.Recipients
         .Display
    End With
 
    'Close the Word document
    objWordDocument.Close
    'Exit Word Application
    objWordApp.Quit
End Sub

VBA Code - Create an Outlook Contact Group from All Email Addresses Occurring in a Word Document

  1. After that, you ought to check Outlook macro settings, ensuring that macro has been enabled.
  2. Later you can back to the previously added macro window.
  3. Eventually, to trigger this new macro, you could press F5 key button or click on the “Run” icon in the toolbar.
  4. Then, you will first be required to specify a name for this contact group, like the following screenshot:Specify a name for this contact group
  5. Lastly, a new contact group will display, shown as the image below:New Contact Group

Beware of All Potential Risks around Outlook

It is known that Outlook is vulnerable to various factors, including power outages, virus infection and malware assaults, hardware issues and software crashes, etc. For example, if your Outlook file gets contracted by viruses, Outlook data will be in danger of a variety of errors and corruption. At that point, it’ll be much better if you have backed up your Outlook data. However, if there is no effective backup, you have no alternative but to take aid of a robust and well quality PST fix tool to repair Outlook.

Author Introduction:

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

Comments are closed.