Outlook Banter

Outlook Banter (http://www.outlookbanter.com/)
-   Outlook and VBA (http://www.outlookbanter.com/outlook-vba/)
-   -   Finding Phonenumber on contacts (http://www.outlookbanter.com/outlook-vba/15501-finding-phonenumber-contacts.html)

Lars Thomsen Nielsen May 23rd 06 01:22 PM

Finding Phonenumber on contacts
 
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).Ite ms
For Each myItem In myContacts
If (myItem.Class = olContact) Then
DummyName = myItem.FullName
DummyPhone = myItem.BusinessTelephoneNumber
End If
Next
End Sub


--
Best regards

Lars Thomsen Nielsen




Guy May 23rd 06 08:10 PM

Finding Phonenumber on contacts
 
What line does it bomb at when you debug?

--
Guy
Forefront Business Solutions
www.forefrontbusinesssolutions.com
www.forefrontbusiness.com


"Lars Thomsen Nielsen" wrote in message
...
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).Ite ms
For Each myItem In myContacts
If (myItem.Class = olContact) Then
DummyName = myItem.FullName
DummyPhone = myItem.BusinessTelephoneNumber
End If
Next
End Sub


--
Best regards

Lars Thomsen Nielsen






Lars Thomsen Nielsen May 23rd 06 08:14 PM

Finding Phonenumber on contacts
 
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



Sue Mosher [MVP-Outlook] May 31st 06 04:45 AM

Finding Phonenumber on contacts
 
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
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"Lars Thomsen Nielsen" wrote in message ...
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



Lars Thomsen Nielsen June 1st 06 02:06 PM

Finding Phonenumber on contacts
 
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 "

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.I tem(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




All times are GMT +1. The time now is 08:56 PM.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2006 OutlookBanter.com