Create a New Contact in Outlook

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

Post Reply
User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Create a New Contact in Outlook

Post by Marcus Tettmar » Fri Jan 20, 2006 3:06 pm

This script pops up a dialog for the new contact details and creates a new contact entry in Outlook. This could be assigned a hotkey as a quick way to enter a new contact, or you might want to use the code that adds the contact in a script that takes contact data from an input file or parses it from an email. It could form the basis for an import script or a way to integrate customer feedback emails with Outlook for example.

VBSTART
Sub NewContact(Name,Email,Phone,Street,City,State,Zip)
Dim objOutlook
Dim itmContact
Dim strMsg

Const olContactItem = 2

'Create Outlook Object and Contact Item
Set objOutlook = CreateObject("Outlook.application")
Set itmContact = objOutlook.CreateItem(olContactItem)


itmContact.FullName = Name
itmContact.EMail1Address = Email
itmContact.PrimaryTelephoneNumber = Phone
itmContact.BusinessAddressStreet = Street
itmContact.BusinessAddressCity = City
itmContact.BusinessAddressState = State
itmContact.BusinessAddressPostalCode = Zip

'Save and display the Contact
itmContact.Save
itmContact.Display
'you might want to remove the display line - it just proves it works

'Clean up
Set itmContact = Nothing
Set objOutlook = Nothing
End Sub
VBEND

Dialog>dlgNewContact
Caption=Add Contact
Width=356
Height=396
Top=CENTER
Left=CENTER
Max=0
Min=0
Close=1
Resize=0
Label=Name,16,8,true
Label=Email,16,56,true
Label=Phone,16,104,true
Label=Street Address,16,152,true
Label=City,16,256,true
Label=State,16,304,true
Label=Zip,128,304,true
Edit=Name,16,24,217,
Edit=Email,16,72,217,
Edit=Phone,16,120,217,
Memo=Address,16,168,217,73,
Edit=City,16,272,217,
Edit=State,16,320,97,
Edit=Zip,128,320,105,
Button=Add,256,320,73,25,1
EndDialog>dlgNewContact

Show>dlgNewContact,r
If>r=1
Let>name=dlgNewContact.Name
Let>email=dlgNewContact.Email
Let>phone=dlgNewContact.Phone
Let>street=dlgNewContact.Address
Let>city=dlgNewContact.City
Let>state=dlgNewContact.State
Let>zip=dlgNewContact.zip
VBRun>NewContact,name,email,phone,street,city,state,zip
Endif
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Jan 26, 2009 10:07 am

Apparently if you use Norton Antivirus you may get errors when running the above script. I am told the solution is to change the following line:

Set objOutlook = CreateObject("Outlook.application")

to:

Set objOutlook = CreateObject("Outlook.application","localhost")

Thanks to Uwe Pfeiffer for the tip.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts