Import Contacts into Outlook 2003 from CSV

Posted on 2006-05-26
Last Modified: 2008-02-01
Currently I have a CSV file, non-standard headers sadly (as in ADDR1 instead of Address1), and I need it to import each record into Outlook as a contact.

I can do it manually but I want to do it using VB.NET (Visual Studio 2005 if it matters).

I know there are better ways but what I was considering was to read the CSV into an array and split the records up. Then put that into Outlook.

You would just Loop this for each record I assume:
        Dim olApp As Outlook.Application
        olApp = CreateObject("Outlook.Application")
        Dim olNs As Outlook.NameSpace
        olNs = olApp.GetNamespace("MAPI")
        Dim olItem As Outlook.ContactItem
        olItem = olApp.CreateItem(olContactItem)
        With olItem
            .FullName = Name
            .Birthday = BDay
            .CompanyName = Company
            .HomeTelephoneNumber = Phone
            .Email1Address = Email
            .JobTitle = Job
            .HomeAddress = ADDR
        End With

The problem I have is loading the CSV and splitting it up into variables that I can loop through.
Also the actual data I need is only Name, Company, and Phone number. The rest is just a bonus. I'm eventually going to schedule this to happen weekly, no Forms needed just a Console App.
Question by:BiSHGoD
    LVL 44

    Expert Comment

    Hi BiSHGoD,

    a few weeks ago i wrote a few scripts on this site doing this and a bit more, but they are VBS so you can add them to the task scheduler

    for the fun of it [well almost] this is your console version based on c:\contacts.csv
    you don't need the headers but add the fields based on the column in the csv
    didn't add robust error handling only a simple try catch and a finally to clean up
    if you test it on a copy of your data first, and compile it into an exe you can add it to the task scheduler for automatic runs

    Imports System.IO

    Module Module1

      Sub Main()
        Dim objNS As Object, oOlFolder As Object, objOutlook As Object
        Dim myItems As Object, objContact As Object

        Const olFolderContacts = 10


          objOutlook = CreateObject("Outlook.Application")
          objNS = objOutlook.GetNamespace("MAPI")
          oOlFolder = objNS.GetDefaultFolder(olFolderContacts) ' this will add them to the default contacts
          myItems = oOlFolder.Items

          Dim strContact() As String
          Dim strLine As String
          If System.IO.File.Exists("c:\contacts.csv") Then
            Dim objstreamreader As StreamReader = System.IO.File.OpenText("test.txt")
            strLine = objstreamreader.ReadLine
            Do Until strLine Is Nothing

              strContact = strLine.Split(",")
              objContact = myItems.Add("IPM.Contact.CTXContacts")
              objContact.FullName = strContact(0)
              objContact.CompanyName = strContact(1)
              objContact.Email1Address = strContact(2)
              objContact.BusinessTelephoneNumber = strContact(3)
              objContact.HomeTelephoneNumber = strContact(4)
              objContact.BusinessFaxNumber = strContact(5)
              objContact.MobileTelephoneNumber = strContact(6)
              objContact.BusinessAddress = strContact(7)
              objContact.Department = strContact(8)
              objContact.OfficeLocation = strContact(9)
              objContact.ManagerName = strContact(10)
              objContact.Body = strContact(11)

              strLine = objstreamreader.ReadLine()
          End If

        Catch ex As Exception

          myItems = Nothing
          oOlFolder = Nothing
          objNS = Nothing
          objOutlook = Nothing
          objContact = Nothing
        End Try

      End Sub

    End Module

    share what you know, learn what you don't

    Author Comment

    Sorry, been a bit busy that I forgot to respond.

    That code snippet didn't work in my environment. I already have some code, above, and would have liked to build on that.

    Consequently I did figure out how to code it myself in VB.NET.

    Accepted Solution

    PAQed with no points refunded (of 350)

    Community Support Moderator

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
    It’s quite interesting for me as I worked with Excel using for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now