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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to access MSOutlook Address Book using VB?

Status
Not open for further replies.

GNMN

Programmer
Oct 14, 2003
20
AP
Anybody knows how to access Outlook Address book using VB. Thanks!

Gene
 
GNMN,
For your general question, here is a general approach.
Start with declering ..
Code:
Dim objOutlook As Outlook.Application
Dim myNSpace As Outlook.NameSpace
Dim myAdList As Outlook.AddressList
Dim myAdEntry As Outlook.AddressEntry
Dim myMberEntry As Object
Dim YourAddressList as String
Dim YourEntry as String
Create a new Outlook instance
Code:
Set objOutlook = New Outlook.Application
Get the NameSpace
Code:
Set myNSpace = objOutlook.GetNamespace("MAPI")
Get your address list you need
Code:
Set myAdList = myNSpace.AddressLists(YourAddressList)
Get all the entries in that address list
Code:
Set myAdEntry = myAdList.AddressEntries(YourEntry)
and for each one of them
Code:
For Each myMberEntry In myAdEntry.Members

       do something

Next
and when done, dont forget to clean up the mess ...
Code:
    Set myAdEntry = Nothing
    Set myAdList = Nothing
    Set myNSpace = Nothing
    objOutlook.Quit
    Set objOutlook = Nothing

If you need something more, just post.
 
Thank you, JerryKlmns.

All I want to do is that I have a command button "To" caption as with MS outlook new message window. When I click this button, an address book window will appear and then will select the recipients, then when I click OK, all the selected recipients will be copied on text field.

Appreciate if you could publish the running code for this function.

Regards!



Gene
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top