title: How to check if contact information exists in my Outlook contacts list?
body: <p>I have code which adds contacts from a worksheet to my Outlook contacts. Each Contact is on a separate line and has 5 columns with First Name, Last name, Email Address, Company and Mobilephone Number.</p>
  <p>How do I add only those lines from the worksheet, which aren't in my contacts, so it doesn't create duplicates?</p>
  <pre><code>Sub ExcelWorksheetDataAddToOutlookContacts3()
      
      Dim oApplOutlook As Object
      Dim oNsOutlook As Object
      Dim oCFolder As Object
      Dim oDelFolder As Object
      Dim oCItem As Object
      Dim oDelItems As Object
      Dim lLastRow As Long, i As Long, n As Long, c As Long
      
      'determine last data row in the worksheet:
      lLastRow = Sheets(&quot;Sheet1&quot;).Cells(Rows.Count, &quot;A&quot;).End(xlUp).Row
      
      'Create a new instance of the Outlook application,
      ' if an existing Outlook object is not available.
      'Set the Application object as follows:
      On Error Resume Next
      Set oApplOutlook = GetObject(, &quot;Outlook.Application&quot;)
      
      'if an instance of an existing Outlook object is not available,
      ' an error will occur (Err.Number = 0 means no error):
      If Err.Number &lt;&gt; 0 Then
          Set oApplOutlook = CreateObject(&quot;Outlook.Application&quot;)
      End If
      
      'disable error handling:
      On Error GoTo 0
      
      'use the GetNameSpace method to instantiate
      ' (ie. create an instance) a NameSpace object variable,
      ' to access existing Outlook items.
      'Set the NameSpace object as follows:
      Set oNsOutlook = oApplOutlook.GetNamespace(&quot;MAPI&quot;)
      
      '----------------------------
      
      'Empty the Deleted Items folder in Outlook so that
      ' when you quit the Outlook application you bypass the prompt:
      ' Are you sure you want to permanently delete all the items
      '  and subfolders in the &quot;Deleted Items&quot; folder?
      
      'set the default Deleted Items folder:
      'The numerical value of olFolderDeletedItems is 3.
      'The following code has replaced the Outlook's built-in 
      ' constant olFolderDeletedItems by its numerical value 3.
      Set oDelFolder = oNsOutlook.GetDefaultFolder(3)
      'set the items collection:
      Set oDelItems = oDelFolder.Items
      
      'determine number of items in the collection:
      c = oDelItems.Count
      
      'start deleting from the last item:
      For n = c To 1 Step -1
          oDelItems(n).Delete
      Next n
      
      '----------------------------
      
      'set reference to the default Contact Items folder:
      'The numerical value of olFolderContacts is 10.
      'The following code has replaced the Outlook's built-in 
      ' constant olFolderContacts by its numerical value 10.
      Set oCFolder = oNsOutlook.GetDefaultFolder(10)
      
      'post each row's data on a separate contact item form:
      For i = 2 To lLastRow
      
          'Using the Items.Add Method to create
          ' a new Outlook contact item in the default Contacts folder.
          Set oCItem = oCFolder.Items.Add
          'display the new contact item form:
          oCItem.Display
          
          'set properties of the new contact item:
          With oCItem
              .firstName = Sheets(&quot;Sheet1&quot;).Cells(i, 1)
              .LastName = Sheets(&quot;Sheet1&quot;).Cells(i, 2)
              .Email1Address = Sheets(&quot;Sheet1&quot;).Cells(i, 3)
              .CompanyName = Sheets(&quot;Sheet1&quot;).Cells(i, 4)
              .MobileTelephoneNumber = Sheets(&quot;Sheet1&quot;).Cells(i, 5)
          End With
          
          'close the new contact item form after saving:
          'The numerical value of olSave is 0.
          'The following code has replaced the Outlook's built-in
          ' constant olSave by its numerical value 0.
          oCItem.Close 0
      
      Next i
      
      'quit the Oulook application:
      oApplOutlook.Quit
      
      'clear the variables:
      Set oApplOutlook = Nothing
      Set oNsOutlook = Nothing
      Set oCFolder = Nothing
      Set oDelFolder = Nothing
      Set oCItem = Nothing
      Set oDelItems = Nothing
      
      MsgBox &quot;Successfully Exported Worksheet Data to the Default Outlook Contacts Folder.&quot;
  
  End Sub
  </code></pre>