Solved

Outlook Contact List

Posted on 2011-02-18
2
286 Views
Last Modified: 2012-05-11
I use the code below to get the contact list from Outlook.  It works except when the user is on an exchange server.

If the user is on an exchange server it does not return any data.

Please Help!

Thanks,

============== Code ==============

Option Explicit

Dim objFolder As Outlook.MAPIFolder
Dim objApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim objItem As Outlook.ContactItem
Dim colAdressFolders As Collection


Private Sub Command1_Click()

Dim lngLoop As Long

Set objApp = New Outlook.Application
Set objNS = objApp.GetNamespace("MAPI")
Set colAdressFolders = New Collection
Set objFolder = objNS.Folders.GetFirst ' get root-folder
' recursive loop thrue all folders to collect the references to Adressbooks

For lngLoop = 1 To objFolder.Folders.Count
    If objFolder.Folders.Item(lngLoop).DefaultItemType = olContactItem Then
        RecursiveSearch objFolder.Folders.Item(lngLoop), colAdressFolders
    End If
Next lngLoop

For Each objFolder In colAdressFolders
    For lngLoop = 1 To objFolder.Items.Count
        Set objItem = objFolder.Items(lngLoop)
        MsgBox objItem.EntryID & "  " & objItem.FullName
    Next
Next

End Sub

Private Sub RecursiveSearch(objSubFolder As Outlook.MAPIFolder, colAdrFolders As Collection)
 
Dim lngLoop As Long

If objSubFolder.Items.Count > 0 Then
    'add reference to collection
    colAdrFolders.Add objSubFolder
End If
 
If objSubFolder.Folders.Count > 0 Then
    For lngLoop = 1 To objSubFolder.Folders.Count
        If objFolder.Folders.Item(lngLoop).DefaultItemType = olContactItem Then
            RecursiveSearch objSubFolder.Folders.Item(lngLoop), colAdrFolders
        End If
    Next lngLoop
End If

End Sub



0
Comment
Question by:PhilChapmanJr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 23

Accepted Solution

by:
wdosanjos earned 500 total points
ID: 34929898
Please check the following article.  It may provide some clues.

http://blogs.msdn.com/b/stephen_griffin/archive/2007/03/19/mapi-and-exchange-2007.aspx
0
 
LVL 2

Author Closing Comment

by:PhilChapmanJr
ID: 34931168
Thanks for the help.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

756 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