CDO MAPI Session failing to retrieve user name but Getexchage user

P

paresh

Hi, could anyone please tell me why attached CDO method is failing on some
computer to retrieve users list from my Outlook 2007 add-in? If gives it
says "Activax component cant create object".

The GetExchangeMethod always works but it is slower than CDO.

Any help would be really helpful.

Thanks.

Using CDO:

Dim cdoSession As Object
Dim cdoAddressList As Object
Dim cdoAddressEntries As Object
Dim cdoAddressEntry As Object
' --------------------------------------------------------------
' Create MAPI session and logged into it
' --------------------------------------------------------------
Set cdoSession = CreateObject("MAPI.Session")
cdoSession.Logon "", "", False, False, 0

' --------------------------------------------------------------
' Get all users address list
' --------------------------------------------------------------
Set cdoAddressList = cdoSession.AddressLists.Item("All Users")

' --------------------------------------------------------------
' Get address entries of the global address list
' --------------------------------------------------------------
Set cdoAddressEntries = cdoAddressList.AddressEntries
i = 1

' --------------------------------------------------------------
' Loop through the address entries collection and
' Add each address entry to the static array
' --------------------------------------------------------------
For Each cdoAddressEntry In cdoAddressEntries
ReDim Preserve allUsers(1 To i + 1) As String
allUsers(i) = cdoAddressEntry.Name
i = i + 1
Next

' --------------------------------------------------------------
' objects clean up
' --------------------------------------------------------------
Set cdoAddressList = Nothing
Set cdoAddressEntries = Nothing
Set cdoAddressEntry = Nothing

' --------------------------------------------------------------
' Logoff from MAPI Session
' --------------------------------------------------------------
cdoSession.Logoff
Set cdoSession = Nothing

Using GetExchangeUser method:

Dim i As Integer

i = 1

Dim oEntry As Outlook.AddressEntry

For i = 1 To usersList.Count
Set oEntry = usersList.Item(i)
ReDim Preserve allUsers(1 To i + 1) As String
allUsers(i) = oEntry.GetExchangeUser().Name
i = i + 1
Next
 
S

Sue Mosher [MVP]

The most likely reason is that CDO is not installed on the machine. Outlook
2007 doesn't include CDO. You have to download and install it on each
machine that needs it.
 
S

Sue Mosher [MVP]

The most likely explanation is that CDO is not present on the machine. It's
not part of Outlook and has to be downloaded and installed on every machine
where you want to use it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top