
Creating contacts from selected messages
tags: contacts, create, macro, move, MS Outlook, VBA
0 comments | Add a comment
In Microsoft Outlook it is possible to automatically create a contact from a received e-mail message. For this, the e-mail should be dragged to the “Contacts” folder. As a result, a new contact with name, last name and e-mail address is created on the basis of the e-mail’s sender's data. The body of the message is saved in the notes field. If you are using MS Outlook 2003, this procedure is the easiest to do in “Folder list” view.
This procedure allows to create new contacts in a very convenient way. However, sometimes it is necessary to create contacts from a number of e-mails. If, for example, someone receives a lot of messages, or if they want to create contacts from messages received earlier, after selecting multiple emails and moving them to the “Contacts” folder, Microsoft Outlook creates only one contact with the notes field filled with multiple message bodies, instead of expected number of separate contacts. This feature is useless for most of users.
If we want to create many separate contacts from a selected number of e-mails, the macro below will do the trick.
Sub ContactsFromMails() Dim contactFolder As MAPIFolder, item As Object, oNewContact As ContactItem, mailCopy As Object Set contactFolder = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderContacts) For Each item In Application.ActiveExplorer.Selection Set mailCopy = item.Copy Set oNewContact = item.Move(contactFolder) oNewContact.Attachments.Remove (1) '(*1) oNewContact.Body = "" '(*2) oNewContact.Save Next Set contactFolder = Nothing Set mailCopy = Nothing Set oNewContact = Nothing End Sub
The macro creates new contacts from selected e-mails in the default contact folder. After creating a new contact, the original e-mail is added to the contact as an attachment, also the notes field also contains the message body. Then, the macro removes the attachment and the message body from the contact. If we want to keep the original e-mail attached, line with (*1) comment should be removed. If the message body should be stored in the notes field of the contact, line with (*2) should be removed.
© All rights reserved. No part or whole of this article may not be reproduced or published without prior permission.