By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,702 Members | 1,771 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,702 IT Pros & Developers. It's quick & easy.

Outlook Contacts

100+
P: 102
Background:

VS 2015 - VB Windows Form Application
SQL Server 2008
Outlook PRO 2016

I want to read my Outlook contacts (global address list) and put them in a datagridview or combo box. I have found some routines on the web but they do no work. I found this one but I get an empty combobox. What is wrong?

Thanks in advance for your help.

Expand|Select|Wrap|Line Numbers
  1. Imports System.Reflection
  2. Imports Microsoft.Office.Interop
  3. Public Class Form1
  4.  
  5.     Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
  6.         Dim objOutlook As Microsoft.Office.Interop.Outlook._Application
  7.         'Outlook Namespace will be current session
  8.         Dim objNS As Microsoft.Office.Interop.Outlook._NameSpace
  9.  
  10.         'Initialise objects created in Form Load
  11.         objOutlook = New Microsoft.Office.Interop.Outlook.Application()
  12.         objNS = objOutlook.Session
  13.  
  14.         'Get the Contact folder
  15.         Dim objAddressList As Microsoft.Office.Interop.Outlook.MAPIFolder
  16.         objAddressList = objNS.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderContacts)
  17.  
  18.         'Get all the contacts
  19.         Dim objItems As Microsoft.Office.Interop.Outlook.Items = objAddressList.Items
  20.         Dim objContact As Microsoft.Office.Interop.Outlook.ContactItem
  21.  
  22.  
  23.         For j = 1 To objItems.Count
  24.             If TypeOf (objContact) Is Microsoft.Office.Interop.Outlook.ContactItem Then
  25.                 objContact = objItems(j)
  26.                 Me.ComboBox1.Items.Add(objContact.Email1Address)
  27.             End If
  28.         Next
  29.  
  30.  
  31.         'clear memory
  32.         objContact = Nothing
  33.         objItems = Nothing
  34.         objAddressList = Nothing
  35.     End Sub
  36.  
  37.  
  38.  
  39. End Class
Jan 18 '17 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.