Some users hope to create a new contact group for the senders of several emails in Outlook. This article will look at this issue and teach you how to quickly achieve it with Outlook VBA.
At times, you may want to create an Outlook contact group for all the senders of several selected emails. For example, you and these senders will be responsible for a new project together. So you must have a great deal of email communication with them. In this case, it will be much convenient for you to create a new contact group for them. Now that you’ve received many emails from them, you must hope to a contact group directly from these emails. Manually creating it will be rather time-consuming. Fortunately, you can use Outlook VBA to realize it in quick time. The followings are the detailed steps as well as the concrete VBA codes.
Create a Contact Group with the Senders of the Selected Emails
- For a start, launch Outlook and press “Alt + F11” key buttons.
- At once, you’ll enter the “Microsoft Visual Basic for Applications” window.
- Then you need to open a module, which is not in use, and copy the following codes into it.
Sub CreateContactGroupforEmailSenders() Dim objSelection As Selection Dim objItem As Object Dim objMail As MailItem Dim objTempMail As MailItem Dim objTempMailRecipients As Recipients Dim objContactGroup As DistListItem Set objSelection = Outlook.Application.ActiveExplorer.Selection Set objTempMail = Outlook.Application.CreateItem(olMailItem) Set objTempMailRecipients = objTempMail.Recipients For Each objItem In objSelection If objItem.Class = olMail Then Set objMail = objItem objTempMailRecipients.Add (objMail.SenderEmailAddress) End If Next If (objTempMailRecipients.Count > 0) And (objTempMailRecipients.ResolveAll) Then Set objContactGroup = Outlook.Application.CreateItem(olDistributionListItem) With objContactGroup .DLName = InputBox("Type a name for the new contact group:") .AddMembers objTempMailRecipients 'To directly save, use “.Save” .Display End With objTempMail.Close (olDiscard) End If End Sub
- Subsequently, you can exit the current window and add the new VBA project to Quick Access Toolbar or ribbon. In addition, you need to ensure that your Outlook macro settings are set to permit the macro.
- Eventually, you can have a try. Here we take the inbox emails as examples.
- At first, open the Inbox mail folder and select several emails.
- Then click on the new macro button in Quick Access Toolbar.
- Next you will be required to enter a name for the new contact group.
- Finally a new contact group will display and the senders of the selected emails will be included.
Outlook Errors Can Occur Now and Then
Although Outlook is well-known for its multiple features, it still cannot get rid of errors thoroughly. That is to say, you may come cross various errors in Outlook from time to time. Therefore, it is prudent to get hold of an experienced Outlook PST file error fix tool, like DataNumen Outlook Repair. It is well-versed in coping with Outlook issues.
Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including mdf repair product and outlook repair software products. For more information visit www.datanumen.com