Create Contact Item in Outlook using Visual Basic for Applications

Create Contact Item in Outlook using Visual Basic for Applications

ContactItem

Object exposes various properties which can be used to create a contact and can be saved in outlook for future use. In this PoC I will write a code to read some contact information from a Excel sheet and populate a Contact Item in outlook and save using VBA code.

Code example

Sub createContact()
    'Outlook application object declaration
    Dim oApp As Outlook.Application
    
    'bind current outlook instance
    Set oApp = GetObject("", "Outlook.Application")
    
    
    'Declare object
    Dim oContactItem As ContactItem
    
    'Create new item
    Set oContactItem = oApp.CreateItem(olContactItem)
    
    'Assign proerties
    oContactItem.FirstName = Range("B1")
    oContactItem.BusinessAddress = Range("B2")
    oContactItem.BusinessAddressCity = Range("B3")
    oContactItem.BusinessAddressCountry = Range("B4")
    oContactItem.Business2TelephoneNumber = Range("B5")
    oContactItem.BusinessAddressPostalCode = Range("B6")
    
    'Display
    oContactItem.Display
    
    'Send
    oContactItem.Save
    
    'Close outlook
    oApp.Quit
    'CleanUp
    If Not oContactItem Is Nothing Then
        Set oContactItem = Nothing
    End If
    
    If Not oApp Is Nothing Then
        Set oApp = Nothing
    End If
End Sub

Input

Output

Next >> Create a outlook mail item using VBA code example

Leave a Reply

Your email address will not be published.