View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Jim Thomlinson[_4_] Jim Thomlinson[_4_] is offline
external usenet poster
 
Posts: 1,119
Default Microsoft CDO 1.21 library

Here is the code I was working on if it helps at all

Option Explicit
Const CdoPR_EMS_AB_PROXY_ADDRESSES = &H800F101E
Const g_strMAPILogOn As String = "MS Exchange Settings"
Const g_strAddressList As String = "Global Address List"
Const g_strEMailAddressIdentifier As String = "SMTP"


Sub Test()

MsgBox GetEMailAddress("James Thomlinson")

End Sub


Public Function GetEMailAddress(ByVal strName As String) As String
Dim objSession As MAPI.Session
Dim objField As MAPI.Field
Dim MyAddressList As MAPI.AddressList
Dim MyAddressEntries As MAPI.AddressEntries
Dim MyEntry As MAPI.AddressEntry
Dim SomeEntry As MAPI.AddressEntry
Dim MyRecipient As MAPI.Recipient
Dim v As Variant
Dim strReturnValue As String

'Initialize Local Variables
strReturnValue = "No Address Found" 'Retrun Value if not found

' Create Session object and Logon.
Set objSession = CreateObject("MAPI.Session")
objSession.Logon (g_strMAPILogOn)

'Create the Address list from the Global Address List
Set MyAddressList = objSession.AddressLists(g_strAddressList)
If MyAddressList Is Nothing Then
MsgBox g_strAddressList & " Unavailable!", vbCritical, "Critical
Error"
Exit Function
End If

'Initialize MyAddressEntires with the entries in the Address List
Set MyAddressEntries = MyAddressList.AddressEntries

'Traverse through the entries searching for a match
For Each SomeEntry In MyAddressEntries
Set MyEntry = SomeEntry
If Trim(UCase(strName)) = Trim(UCase(MyEntry.Name)) Then
Set objField = MyEntry.Fields(CdoPR_EMS_AB_PROXY_ADDRESSES)

' PR_EMS_AB_PROXY_ADDRESSES is a multivalued property
(PT_MV_TSTRING).
' Therefore, you need to extract the individual members.
For Each v In objField.Value
If InStr(1, UCase(v), g_strEMailAddressIdentifier) Then
strReturnValue = Mid(v, 6, 256)
Exit For
End If
Next 'Next Field Value
Exit For
End If
Next 'Next Address Entry

'Return Function Value
GetEMailAddress = strReturnValue

'Housekeeping
Set objField = Nothing
Set MyAddressList = Nothing
Set MyAddressEntries = Nothing
Set MyEntry = Nothing
Set MyRecipient = Nothing
objSession.Logoff
Set objSession = Nothing

End Function
--
HTH...

Jim Thomlinson


"Steve" wrote:

What are the other options if I want to call Outlook from Excel. I would
need to get email addresses from Outlook and things of that nature. Also, is
it ok to load CDO.dll on the users computers? It seems that is the only file
missing, and when I copied CDO.dll from my computer to another one of my
computers it seemed to work then.. Is it necessary to install from the CD.


"Jim Thomlinson" wrote:

The CDO library is part of the Outlook install. If it is not installed then
you need to get it installed (you need the office disk and the necessary
permissions to perform an install on the host computer). I did some
developement with CDO but ended up abandoning it because of just these kind
of issues. Also note that CDO operates differently on 2000 depending on what
service pack is installed (extra security prompts the user for approvals and
such).
--
HTH...

Jim Thomlinson


"Steve" wrote:

Good day.

I am designing an Excel solution that will require CDO 1.21 library. How
can I be sure each user has this installed, and if they are using Excel 2000
or less, how can I install it for them via code or an intall routine.

Thanks,