Finding Phonenumber on contacts

  • Thread starter Lars Thomsen Nielsen
  • Start date
L

Lars Thomsen Nielsen

Outlook2003. I would like to get the phonenumbers from the listed
persons in a distributionlist. However I have some problems
defining the right folder. The code below works for my personal
addressbook, but I wish to get it to work with a distribution
list called "All address lists" -> "All Groups" -> "Local list".
I constantly gets problems when trying to change the line with
GetDefaultFolder(olFolderContacts).

Could somebody please help me to get this to work?

Sub FindPhoneNumber()
Dim myOlApp As Outlook.Application
Dim myNamespace As Outlook.NameSpace
Dim myContacts As Outlook.Items
Dim myItems As Outlook.Items
Dim myItem As Object
Dim DummyName As String
Dim DummyPhone As String
Set myOlApp = CreateObject("Outlook.Application")
Set myNamespace = myOlApp.GetNamespace("MAPI")
Set myContacts =
myNamespace.GetDefaultFolder(olFolderContacts).Items
For Each myItem In myContacts
If (myItem.Class = olContact) Then
DummyName = myItem.FullName
DummyPhone = myItem.BusinessTelephoneNumber
End If
Next
End Sub
 
L

Lars Thomsen Nielsen

What line does it bomb at when you debug?

The shown code works fine, but only for my private contacts. I wish to get
the phonenumbers from on of the companies distributionlists ("All address
lists" -> "All Groups" -> "Local list"). However I can't seem to define the
folder correctly :-(

Lars
 
S

Sue Mosher [MVP-Outlook]

GAL address lists are not Outlook folders. You can't use Outlook ContactItem properties with them. See http://www.outlookcode.com/codedetail.aspx?id=594 for a code sample showing how to retrieve a phone number with MAPI properties.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
L

Lars Thomsen Nielsen

See http://www.outlookcode.com/codedetail.aspx?id=594 for a
code sample
showing how to retrieve a phone number with MAPI properties.

Thanx Sue,

I have found another workaround. I have used CDO.

To get ALL the possible information on the person I have made the
following code which saves a file for me with the relevant data
and puts the for me most important data into variables. (I have
cut a lot of the code out):

Sub GetPersonData()
Set myOutlook = CreateObject("Outlook.Application")
Set myMailItem = myOutlook.CreateItem(0)

myMailItem.Recipients.Add "(e-mail address removed)"

Call ReadCDO_Var
Call ReadCDO_VarKode

Set cdoSession = CreateObject("Mapi.session")
cdoSession.Logon , , False, False, 0 'Use the existing Outlook
session.
Set cdoAddrEntry =
cdoSession.GetAddressEntry(myMailItem.Recipients.Item(1).EntryID)

Open StiOgFilNavn For Output As #3
For i = 1 To 453
DummyStreng = ""
DummyStreng = cdoAddrEntry.Fields(CDO_VarKode(i))
If DummyStreng <> "" Then
Print #3, i & vbTab & CDO_Var(i)
Print #3, i & vbTab & DummyStreng
Print #3, ""
'Debug.Print CDO_Var(i) & " = "; DummyStreng
If CDO_Var(i) = "CdoPR_ACCOUNT" Then Initialer =
DummyStreng
If CDO_Var(i) = "CdoPR_BUSINESS_TELEPHONE_NUMBER" Then
TlfNummer = DummyStreng
If CDO_Var(i) = "CdoPR_DISPLAY_NAME" Then Fuldtnavn =
DummyStreng
If CDO_Var(i) = "CdoPR_GIVEN_NAME" Then Fornavn =
DummyStreng
If CDO_Var(i) = "CdoPR_SURNAME" Then Efternavn =
DummyStreng
If CDO_Var(i) = "CdoPR_TITLE" Then Titel = DummyStreng
End If
Next
Close #3
End Sub

Sub ReadCDO_Var()
'Tildeler variabelnavne med tilhørende CDO-kaldenavn
CDO_Var(1) = "CdoPR_7BIT_DISPLAY_NAME"
CDO_Var(2) = "CdoPR_AB_DEFAULT_DIR"
CDO_Var(3) = "CdoPR_AB_DEFAULT_PAB"
CDO_Var(4) = "CdoPR_AB_PROVIDER_ID"
CDO_Var(5) = "CdoPR_AB_PROVIDERS"
CDO_Var(6) = "CdoPR_AB_SEARCH_PATH"
.....
CDO_Var(452) = "CdoPR_XPOS"
CDO_Var(453) = "CdoPR_YPOS"
End Sub

Sub ReadCDO_VarKode()
'Tildeler variabelnavne med tilhørende CDO-kaldekode
CDO_VarKode(1) = &H39FF001E
CDO_VarKode(2) = &H3D060102
CDO_VarKode(3) = &H3D070102
CDO_VarKode(4) = &H36150102
CDO_VarKode(5) = &H3D010102
CDO_VarKode(6) = &H3D051102
.....
CDO_VarKode(452) = &H3F050003
CDO_VarKode(453) = &H3F060003
End Sub
 

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