Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default read outlook contacts

Dear,

i would have a program in excel for select outlook's contacts and fill into
excel. will here any existing solution for?

thanks,
William


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default read outlook contacts

Here is some code that I have used... It returns all of the addresses from
the global address list. The code requires a reference to the CDO 1.??
library. Note that when the code runs a security dialog will ask the user to
allow access to the Address list as this code could be used to propogate
viruses. You may need to change a number of settings to make this work for
your particular application. You will want to look up MAPI and CDO... This is
not simple stuff, so if you are not comfortable with this you may want to
avoid this all together.

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"

Public Sub GetEMailAddress()
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 rng As Range
Dim intCounter As Integer

Set rng = Sheet1.Range("A2")


' 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 Sub
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

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.
intCounter = 0
For Each v In objField.Value
If InStr(1, UCase(v), g_strEMailAddressIdentifier) Then
rng.Offset(0, intCounter).Value = Mid(v, 6, 256)
intCounter = intCounter + 1
End If
Next 'Next Field Value
Set rng = rng.Offset(1, 0)
Next 'Next Address Entry


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

End Sub

--
HTH...

Jim Thomlinson


"William" wrote:

Dear,

i would have a program in excel for select outlook's contacts and fill into
excel. will here any existing solution for?

thanks,
William



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default read outlook contacts

is CDO stand for
Microsoft CDO for windows 2000 library?

thanks,
William

"Jim Thomlinson" ...
Here is some code that I have used... It returns all of the addresses from
the global address list. The code requires a reference to the CDO 1.??
library. Note that when the code runs a security dialog will ask the user
to
allow access to the Address list as this code could be used to propogate
viruses. You may need to change a number of settings to make this work for
your particular application. You will want to look up MAPI and CDO... This
is
not simple stuff, so if you are not comfortable with this you may want to
avoid this all together.

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"

Public Sub GetEMailAddress()
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 rng As Range
Dim intCounter As Integer

Set rng = Sheet1.Range("A2")


' 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 Sub
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

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.
intCounter = 0
For Each v In objField.Value
If InStr(1, UCase(v), g_strEMailAddressIdentifier) Then
rng.Offset(0, intCounter).Value = Mid(v, 6, 256)
intCounter = intCounter + 1
End If
Next 'Next Field Value
Set rng = rng.Offset(1, 0)
Next 'Next Address Entry


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

End Sub

--
HTH...

Jim Thomlinson


"William" wrote:

Dear,

i would have a program in excel for select outlook's contacts and fill
into
excel. will here any existing solution for?

thanks,
William





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default read outlook contacts

Sorry, it should be like "Microsoft CDO 1.21 Library"
--
HTH...

Jim Thomlinson


"William" wrote:

is CDO stand for
Microsoft CDO for windows 2000 library?

thanks,
William

"Jim Thomlinson" ...
Here is some code that I have used... It returns all of the addresses from
the global address list. The code requires a reference to the CDO 1.??
library. Note that when the code runs a security dialog will ask the user
to
allow access to the Address list as this code could be used to propogate
viruses. You may need to change a number of settings to make this work for
your particular application. You will want to look up MAPI and CDO... This
is
not simple stuff, so if you are not comfortable with this you may want to
avoid this all together.

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"

Public Sub GetEMailAddress()
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 rng As Range
Dim intCounter As Integer

Set rng = Sheet1.Range("A2")


' 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 Sub
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

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.
intCounter = 0
For Each v In objField.Value
If InStr(1, UCase(v), g_strEMailAddressIdentifier) Then
rng.Offset(0, intCounter).Value = Mid(v, 6, 256)
intCounter = intCounter + 1
End If
Next 'Next Field Value
Set rng = rng.Offset(1, 0)
Next 'Next Address Entry


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

End Sub

--
HTH...

Jim Thomlinson


"William" wrote:

Dear,

i would have a program in excel for select outlook's contacts and fill
into
excel. will here any existing solution for?

thanks,
William






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Contacts from Excel to Outlook Ergg Excel Discussion (Misc queries) 1 January 20th 10 10:12 PM
How do I export contacts from Excel back to Outlook Contacts? corvettego Excel Discussion (Misc queries) 2 August 17th 09 06:29 PM
Import contacts from outlook Bob Levin Excel Discussion (Misc queries) 10 September 10th 08 10:12 PM
outlook contacts lee Excel Discussion (Misc queries) 0 October 25th 05 08:40 PM
I could really need your help on importing contacts into Outlook (Please?) Jos[_2_] Excel Programming 8 November 17th 03 03:24 AM


All times are GMT +1. The time now is 12:03 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"