Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming VBA / July 2007

Tip: Looking for answers? Try searching our database.

Searching GAL for telephone number

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Matthias - 26 Sep 2005 15:09 GMT
hi,

i would like to search the outlook address book (not contacts) of a running
outlook instance (exchange-session etc established) for an user with a given
telephone number but am a bit overwhelmed by the many api's around.  
nonetheless, by reading documentation i could not find a way of doing this.  
can anyone give me a hint on what to use?

many thanks,
Matthias
Eric Legault [MVP - Outlook] - 26 Sep 2005 19:56 GMT
AFAIK, there is no way to use the Exchange SDK to determine which mailboxes
are currently logged into (even though you can see last login times with
Exchange System Manager).  Perhaps you can use WMI to read this data, I'm not
sure - don't know much about WMI.

From the client side, you could write a VBA macro or COM Add-In to log
application startup/shutdowns, but you would need to do this on every PC
running Outlook.

Other alternatives could be to integrate with Windows Messenger to read
presence status:

Windows Messenger:
http://msdn.microsoft.com/library/en-us/WinMessenger/winmessenger/messenger_entr
y.asp?frame=true


Or build your own messenger app to do this:

Enhancing Rich Client Communications with the Microsoft Real-Time
Communications API (Windows XP Technical Articles):
http://msdn.microsoft.com/library/en-us/dnwxp/html/rtc_enhancerichclient-real-ti
mecomm.asp?frame=true


Anyway, if detecting online presence is not a priority, you can still search
the GAL for a specific business telephone number, but you need to use CDO.  
Here's an example that loops through the entire GAL looking for a user's full
name.  You can easily change it to look for the phone number:

Sub GetGALAddressDetails(UserFullName As String)
On Error Resume Next

   Dim objSession As New MAPI.Session
   Dim objAdds As MAPI.AddressLists
   Dim objAddress As MAPI.AddressEntry
   Dim objGAL As MAPI.AddressList
   Dim objFields As MAPI.Fields, objField As MAPI.Field
   
   objSession.Logon , , , False
   
   If objSession Is Nothing Then Exit Sub
   
   Set objAdds = objSession.AddressLists
   Set objGAL = objAdds.Item("Global Address List")
   For Each objAddress In objGAL.AddressEntries
       If objAddress.DisplayType = CdoUser Or objAddress.DisplayType =
CdoRemoteUser Then
           If InStr(objAddress.Name, UserFullName) > 0 Then
               Set objField = objAddress.Fields(CdoPR_BUSINESS_ADDRESS_CITY)
               If Not objField Is Nothing Then Debug.Print objField.Value:
Set objField = Nothing
               Set objField =
objAddress.Fields(CdoPR_BUSINESS_ADDRESS_COUNTRY)
               If Not objField Is Nothing Then Debug.Print objField.Value:
Set objField = Nothing
               Set objField =
objAddress.Fields(CdoPR_BUSINESS_ADDRESS_POSTAL_CODE)
               If Not objField Is Nothing Then Debug.Print objField.Value:
Set objField = Nothing
               Set objField =
objAddress.Fields(CdoPR_BUSINESS_ADDRESS_STATE_OR_PROVINCE)
               If Not objField Is Nothing Then Debug.Print objField.Value:
Set objField = Nothing
               Set objField =
objAddress.Fields(CdoPR_BUSINESS_ADDRESS_STREET)
               If Not objField Is Nothing Then Debug.Print objField.Value:
Set objField = Nothing
               Set objField = objAddress.Fields(CdoPR_TITLE)
               If Not objField Is Nothing Then Debug.Print objField.Value:
Set objField = Nothing
               Set objField = objAddress.Fields(CdoPR_COMPANY_NAME)
               If Not objField Is Nothing Then Debug.Print objField.Value:
Set objField = Nothing
               Set objField = objAddress.Fields(CdoPR_DEPARTMENT_NAME)
               If Not objField Is Nothing Then Debug.Print objField.Value:
Set objField = Nothing
               Set objField = objAddress.Fields(CdoPR_OFFICE_LOCATION)
               If Not objField Is Nothing Then Debug.Print objField.Value:
Set objField = Nothing
               Set objField = objAddress.Fields(CdoPR_ASSISTANT)
               If Not objField Is Nothing Then Debug.Print objField.Value:
Set objField = Nothing
               Set objField =
objAddress.Fields(CdoPR_BUSINESS_TELEPHONE_NUMBER)
               If Not objField Is Nothing Then Debug.Print objField.Value:
Set objField = Nothing
           End If
       End If
   Next
   
   objSession.Logoff
   
   Set objSession = Nothing
   Set objAdds = Nothing
   Set objAddress = Nothing
   Set objGAL = Nothing
   Set objFields = Nothing
   Set objField = Nothing
End Sub

Signature

Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/

> hi,
>
[quoted text clipped - 6 lines]
> many thanks,
> Matthias
Matthias - 27 Sep 2005 11:50 GMT
thank you very much, Eric.  that was helpful.

i have been playing around something with this and found, that i can iterate
over the values of the fields of my addressentry.  but i cannot (as it is
with cdo) get the names of the predefined values.  since i'm getting errors
when accessing, e.g. CdoPR_OFFICE_TELEPHONE_NUMBER (MAPI_E_NOT_FOUND) i would
like to know where the data that i try to access is stored.  afaik the gal of
outlook (and exchange) 2003 is somehow generated from active directory data.  
do the constants from MAPI.CdoPropTags match to fields in AD ?

again, many thanks,
Matthias
Eric Legault [MVP - Outlook] - 27 Sep 2005 16:30 GMT
If those properties are empty, you will get that error.  So add On Error Resume Next or check for Field objects that are Nothing.

--
Eric Legault (MVP - Outlook, MCDBA, old school WOSA MCSD, B.A.)
Blog: http://blogs.officezealot.com/legault 
Try Picture Attachments Wizard for Outlook!
http://www.collaborativeinnovations.ca

 thank you very much, Eric.  that was helpful.

 i have been playing around something with this and found, that i can iterate
 over the values of the fields of my addressentry.  but i cannot (as it is
 with cdo) get the names of the predefined values.  since i'm getting errors
 when accessing, e.g. CdoPR_OFFICE_TELEPHONE_NUMBER (MAPI_E_NOT_FOUND) i would
 like to know where the data that i try to access is stored.  afaik the gal of
 outlook (and exchange) 2003 is somehow generated from active directory data.  
 do the constants from MAPI.CdoPropTags match to fields in AD ?

 again, many thanks,
 Matthias
J Streger - 17 Jul 2007 18:06 GMT
I know the address book has a search function. If there any way to
programatically serach through the address book, rather than looping through
every single entry?

Signature

*********************
J Streger
MS Office Master 2000 ed.
MS Project White Belt 2003

User of MS Office 2003

> AFAIK, there is no way to use the Exchange SDK to determine which mailboxes
> are currently logged into (even though you can see last login times with
[quoted text clipped - 103 lines]
> > many thanks,
> > Matthias
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.