Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I Extract phone number out of Global Address Book 1

Status
Not open for further replies.

DCCoolBreeze

Programmer
Jul 25, 2001
208
US
How can I pull phone numbers out of the global address book using vba? Outlook 2002 is what I am using...
 
If I understand correctly, you need to import Outlook Phone Book to Access.
In that case go to:
File -> Get External Data -> Import...
You'll reach the Browse Window. In "Files of Type:" choose "Exchange()"
I think the rest you'll figure out by yourself.

Tell me whether it helped.
Good luck
 
Um after playing around with this, the only thing I was able to do in code, is either completely download the global address list, or display the ID, Name, Address, and Class of each item on the global address list. Now, most of the items on my list, do have the extension number after the person's full name as a part of the Name. But I'm assuming that you want the phone number from the specific person's property. I haven't had any luck with that. If I remember correctly, there are a few articles on MSDN that provide codes on how to get all info from the global address list by referencing to the MS CDO library.
Sorry I can't help much, maybe this will give you some ideas, if not, ignore it :)
 
This is exactly what I got...just a few of the fields. I will check MSDN
 
Hey, I found this piece of code in my hard drive today, looks like the sample code from MSDN that does what you want. I probably just copied down before just in case I need to use it. Sorry I don't remember exactly which article it's from, but I'll just paste it here, maybe you can pick out some useful stuff.

Option Explicit


Private Sub Command1_Click()

Const strServer = "MyServer"
Const strMailbox = "MyMailbox"

Dim objSession As MAPI.Session
Dim objAddrEntries As AddressEntries
Dim objAddressEntry As AddressEntry
Dim objFilter As AddressEntryFilter
Dim strProfileInfo As String

strProfileInfo = strServer & vbLf & strMailbox

Set objSession = CreateObject("MAPI.Session")
objSession.Logon , , False, False, , True, strProfileInfo
Set objAddrEntries = objSession.AddressLists _
("Global Address List").AddressEntries
Set objFilter = objAddrEntries.Filter
objFilter.Fields.Add CdoPR_SURNAME, "LastName"
objFilter.Fields.Add CdoPR_GIVEN_NAME, "FirstName"
On Error Resume Next
For Each objAddressEntry In objAddrEntries
Debug.Print objAddressEntry.Name
Debug.Print "E-address: " & objAddressEntry.Address
Debug.Print "Given Name: " & _
objAddressEntry.Fields(CdoPR_GIVEN_NAME).Value
Debug.Print "Initials: " & objAddressEntry.Fields _
(CdoPR_INITIALS).Value
Debug.Print "Surname: " & objAddressEntry.Fields _
(CdoPR_SURNAME).Value
Debug.Print "Display Name: " & objAddressEntry.Fields _
(CdoPR_DISPLAY_NAME).Value
Debug.Print "Alias: " & _
objAddressEntry.Fields(CdoPR_ACCOUNT).Value
Debug.Print "Title: " & _
objAddressEntry.Fields(CdoPR_TITLE).Value
Debug.Print "Company Name: " & objAddressEntry.Fields _
(CdoPR_COMPANY_NAME).Value
Debug.Print "Office Location: " & objAddressEntry.Fields _
(CdoPR_OFFICE_LOCATION).Value
Debug.Print "Office Phone 1: " & objAddressEntry.Fields _
(CdoPR_OFFICE_TELEPHONE_NUMBER).Value
Debug.Print "Office Phone 2: " & objAddressEntry.Fields _
(CdoPR_OFFICE2_TELEPHONE_NUMBER).Value
Debug.Print "Business Fax: " & objAddressEntry.Fields _
(CdoPR_BUSINESS_FAX_NUMBER).Value
Debug.Print "Mobile Phone: " & objAddressEntry.Fields _
(CdoPR_MOBILE_TELEPHONE_NUMBER).Value
Debug.Print "Pager: " & objAddressEntry.Fields _
(CdoPR_PAGER_TELEPHONE_NUMBER).Value
Debug.Print "Assistant: " & objAddressEntry.Fields _
(CdoPR_ASSISTANT).Value
Debug.Print "Assistant Phone: " & objAddressEntry.Fields _
(CdoPR_ASSISTANT_TELEPHONE_NUMBER).Value
Debug.Print "Home Phone 1: " & objAddressEntry.Fields _
(CdoPR_HOME_TELEPHONE_NUMBER).Value
Debug.Print "Home Phone 2: " & objAddressEntry.Fields _
(CdoPR_HOME2_TELEPHONE_NUMBER).Value
Debug.Print "Home Fax: " & objAddressEntry.Fields _
(CdoPR_HOME_FAX_NUMBER).Value
Debug.Print "Home Street: " & objAddressEntry.Fields _
(CdoPR_HOME_ADDRESS_STREET).Value
Debug.Print "Home City: " & objAddressEntry.Fields _
(CdoPR_HOME_ADDRESS_CITY).Value
Debug.Print "Home State: " & objAddressEntry.Fields _
(CdoPR_HOME_ADDRESS_STATE_OR_PROVINCE).Value
Debug.Print "Home Postal Code: " & objAddressEntry.Fields _
(CdoPR_HOME_ADDRESS_POSTAL_CODE).Value
Debug.Print "Home Country: " & objAddressEntry.Fields _
(CdoPR_HOME_ADDRESS_COUNTRY).Value
Debug.Print "Manager Name: " & objAddressEntry.Fields _
(CdoPR_MANAGER_NAME).Value
Debug.Print "Manager Name: " & objAddressEntry.Manager
Next
objSession.Logoff
Set objFilter = Nothing
Set objAddrEntries = Nothing
Set objSession = Nothing

End Sub
 
Hi, I'm trying to download personnel from Outlook and it's working fine but I can't seem to get Office Number from the entries. I'm using code similar to the below but in VBA and I don't know what the number(&H3A19001E-something like that) would be for office number.

CONST strServer = "MyServer"
CONST strMailbox = "MyMailbox"
CONST CdoPR_GIVEN_NAME = &H3A06001E 'First Name
CONST CdoPR_INITIALS = &H3A0A001E 'Initials
CONST CdoPR_SURNAME = &H3A11001E 'Last Name
CONST CdoPR_DISPLAY_NAME = &H3001001E 'Display Name
CONST CdoPR_ACCOUNT = &H3A00001E 'Alias
CONST CdoPR_TITLE = &H3A17001E 'Title
CONST CdoPR_COMPANY_NAME = &H3A16001E 'Company
CONST CdoPR_OFFICE_LOCATION = &H3A19001E 'Office
CONST CdoPR_HOME_TELEPHONE_NUMBER = &H3A09001E 'Phone
CONST CdoPR_HOME2_TELEPHONE_NUMBER = &H3A2F001E 'Home Phone 2
CONST CdoPR_HOME_FAX_NUMBER = &H3A25001E 'Home Fax
CONST CdoPR_HOME_ADDRESS_STREET = &H3A5D001E 'Address
CONST CdoPR_HOME_ADDRESS_CITY = &H3A59001E 'City
CONST CdoPR_HOME_ADDRESS_STATE_OR_PROVINCE = &H3A5C001E 'State
CONST CdoPR_HOME_ADDRESS_POSTAL_CODE = &H3A5B001E 'Zip
CONST CdoPR_HOME_ADDRESS_COUNTRY = &H3A5A001E 'Country
CONST CdoPR_MANAGER_NAME = &H3A4E001E 'Manager
CONST CdoPR_OFFICE_TELEPHONE_NUMBER = &H3A08001E 'Business
'Phone
CONST CdoPR_OFFICE2_TELEPHONE_NUMBER = &H3A1B001E 'Business
'Phone 2
CONST CdoPR_BUSINESS_FAX_NUMBER = &H3A24001E 'Fax
CONST CdoPR_ASSISTANT = &H3A30001E 'Assistant
CONST CdoPR_ASSISTANT_TELEPHONE_NUMBER = &H3A2E001E 'Asistant
'Phone Number
CONST CdoPR_MOBILE_TELEPHONE_NUMBER = &H3A1C001E 'Mobile
CONST CdoPR_PAGER_TELEPHONE_NUMBER = &H3A21001E 'Pager

Dim objSession
Dim objAddrEntries
Dim objAddressEntry
Dim objFilter
Dim strProfileInfo

strProfileInfo = strServer & vbLf & strMailbox

Set objSession = CreateObject("MAPI.Session")
objSession.Logon , , False, False, , True, strProfileInfo
Set objAddrEntries = objSession.AddressLists _
("Global Address List").AddressEntries

'Create a filter for a user.
Set objFilter = objAddrEntries.Filter
objFilter.Fields.Add cdoPR_SURNAME, "LastName"
objFilter.Fields.Add CdoPR_GIVEN_NAME, "FirstName"
 
I figured it out...in case anyone is wondering:

There are customizable fields in Outlook, which is where the office number I was looking for was. This page has a list of the custom cdo attributes

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top