Welcome to Excel Avon
Create Contact in Outlook
DOWNLOAD THE USED EXCEL FILE FROM HERE>>
In today’s post, we will show you How to Create contact in outlook in Excel VBA, In this post we will work with Module as we created with Module in previous post.
We told in previous post How to Convert Excel Range to Html In Excel VBA, this post is totally different from that post, The Contact module in Outlook 2007 gives you a resource for managing and tracking contracts, addressing emails by entering a person’s name instead of trying to remember the email address, and creating distribution lists for emailing groups without having to re-enter everyone into the email every time you send a group email.
In this way we can create the contact as you are seeing in the image.
Let us understand how to create a contact in Outlook with the help of VBA.
How to Create Contact in Outlook Using Excel VBA
As we taught you how to insert a module when we were working with modules, as we have learned in many posts so far, you can insert modules. Let us teach you how we insert the module. Let’s understand, then we have to go like last time, first go to the Developer Tab, then click on the option of Visual Basic as shown in the image below.
On opening in VBE, you have to go to Insert and then Module has to be inserted, as can be seen in the image.
Go to Tools and then select References as shown in the below screenshot. scroll down in the Reference Object library and select “Microsoft Outlook 16.0 Object Library” to make it available for Excel VBA.
Once the module is inserted, and the library is activated, we’ll write a subroutine to Sub Create Contact().
Sub CreateContact() End Sub
We will Declare the variable Outlook Application.
Sub CreateContact() Dim olApp As New Outlook.Application End Sub
Declare the variable Outlook Contact item.
Sub CreateContact() Dim olApp As New Outlook.Application Dim cItem As Outlook.ContactItem End Sub
Create new Items.
Sub CreateContact() Dim olApp As New Outlook.Application Dim cItem As Outlook.ContactItem Set cItem = olApp.CreateItem(olContactItem) End Sub
Now we will assign properties First Name. Last Name and email address
Sub CreateContact() Dim olApp As New Outlook.Application Dim cItem As Outlook.ContactItem Set cItem = olApp.CreateItem(olContactItem) cItem.FirstName = "John" End Sub
Now we will assign properties Last Name.
Sub CreateContact() Dim olApp As New Outlook.Application Dim cItem As Outlook.ContactItem Set cItem = olApp.CreateItem(olContactItem) cItem.FirstName = "John" cItem.LastName = "Smith" End Sub
Now we will assign properties Email Address.
Sub CreateContact() Dim olApp As New Outlook.Application Dim cItem As Outlook.ContactItem Set cItem = olApp.CreateItem(olContactItem) cItem.FirstName = "John" cItem.LastName = "Smith" cItem.Email1Address = "abcd@gmail.com" End Sub
Now we will give the save command, save command is for for saving item in outlook.
Sub CreateContact() Dim olApp As New Outlook.Application Dim cItem As Outlook.ContactItem Set cItem = olApp.CreateItem(olContactItem) cItem.FirstName = "John" cItem.LastName = "Smith" cItem.Email1Address = "abcd@gmail.com" cItem.Save End Sub
Click on Run button
After running code we will open the Outlook application and then we will see that we have created the contact. After opening Outlook, we see that the name we created has been created and the email has also been saved.
Therefore, I hope that you have understood How to Create Contact in Outlook Using Excel VBA, maybe if you do not understand some options, then you can comment us, which we will answer soon and for more information, you can follow us on Twitter, Instagram, LinkedIn and you can also follow on YouTube.
DOWNLOAD THE USED EXCEL FILE FROM HERE>>
You can also see well-explained video here about How to Create Contact in Outlook Using Excel VBA