Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Outlook Contact List

Posted on 2011-02-18
2
Medium Priority
?
293 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
2 Comments
 
LVL 23

Accepted Solution

by:
wdosanjos earned 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

916 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