Automatically Create Contacts
I often find myself creating a Outlook contact from the signature in an email or some text in a work document. Rather than do it by hand each time, I have put together a few vba commands and a new vba class to parse the text on the clipboard and create a new contact from what it gathers.
To set it up, in ThisOutlookSession add:
Public Sub ParseClipboard() Dim Selection As DataObject Dim SelectionStr As String Set Selection = New DataObject Selection.GetFromClipboard SelectionStr = Selection.GetText CreateAddrFromStr SelectionStr End Sub
In a new module add:
Option Explicit Public Sub CreateAddrFromStr(str As String) Dim MyContact As ContactItem Debug.Print "create" Set MyContact = Outlook.CreateItem(olContactItem) MyContact.Display Dim MyParsed As ContactObj Set MyParsed = New ContactObj Debug.Print str MyParsed.Parse str MyContact.FullName = MyParsed.Name MyContact.Title = MyParsed.Title MyContact.CompanyName = MyParsed.Company MyContact.BusinessTelephoneNumber = MyParsed.PhoneWork MyContact.BusinessFaxNumber = MyParsed.PhoneFax MyContact.MobileTelephoneNumber = MyParsed.PhoneMobile MyContact.HomeTelephoneNumber = MyParsed.PhoneHome MyContact.BusinessAddress = MyParsed.Address MyContact.Email1Address = MyParsed.Email1 MyContact.Email2Address = MyParsed.Email2 MyContact.Email3Address = MyParsed.Email3 MyContact.Body = MyParsed.Note End Sub
Then you need to import ContactObj.cls which will create the ContactObj Class Module.
There are a handful of reference that you will need to setup in order to use the regex and pull from the clipboard. In the VBA editor, go to Tools then References and add:
- Microsoft VBScript Regular Expressions 5.5
- Microsoft Forms 2.0 Obj Library
- Microsoft Visual Basic for Applications Extensible 5.5
If MS Forms 2.0 isn't listed, you can browse to
c:\windows\system32\fm20.dll
.
Finally, you probably want to add a toolbar button to easily use:
- Right click on the the toolbar
- Click Customize
- On the Command tab select Macros on the left, find Project1.ThisOutlookSession.ParseClipboard and drag it to the toolbar
Now a new contact will be created from whatever text you have copied when you click the new button