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

Outlook Address Book..Does any code Exist for this?

Status
Not open for further replies.

lulo

Programmer
Jan 24, 2001
51
0
0
US
Anybody,
I have tried to display a list of names from outlook to my visual basic application but no luck.
I have tried MSDN Help files but msnd does not offer this type of help.
Does anybody recommend something.

Your comments are greatly appreciated.

Thank you

Lulo
 
'There are many other useful properties you can set
'for Contacts. View the object browser for a list


Sub AddContact()
Dim appOutLook As Outlook.Application
Dim conOutLook As Outlook.ContactItem
Set appOutLook = CreateObject("Outlook.Application")
Set conOutLook = appOutLook.CreateItem(olContactItem)
With conOutLook
'There are many other useful properties you can set
'for Contacts. View the object browser for a list

'of other properties.
.FirstName = "John"
.LastName = "Doe"
.BusinessTelephoneNumber = "(202)555-5555"
.Email1Address = "JDoe"
.Birthday = "1/10/61"
.CompanyName = "ACME Company"
.JobTitle = "Engineer"
.Save
End With
Set conOutLook = Nothing
Set appOutLook = Nothing
End Sub
Eric De Decker
vbg.be@vbgroup.nl

License And Copy Protection AxtiveX.

Download Demo version on my Site:
 
I've used the code below but haven't checked it lately.

Steve King

Public Function GetContact(strName As String)

On Error Resume Next

Dim oApp As Outlook.Application
Dim myNameSpace As NameSpace
Dim myAddressLists As AddressLists
Dim myAddressList As AddressList
Dim myAddrEntries As AddressEntries
Dim myEntry As AddressEntry
Dim intNameLen As Integer
Dim intCnt As Integer
Dim intCnt2 As Integer
Dim strUser As String
Dim strTempAddr As String

Set oApp = GetOutlook()
Set myNameSpace = oApp.GetNamespace("MAPI")
intNameLen = Len(strName)

For Each myAddressList In myNameSpace.AddressLists
If myAddressList.Name = "Contacts" _
Or myAddressList.Name = "Personal Address Book" Then
For Each myEntry In myAddressList.AddressEntries
If InStr(1, myEntry.Name, strName) Then
strTempAddr = myEntry.Address
If InStr(1, strTempAddr, "=") Then
strTempAddr = GetShortAddr(myEntry.Members(intCnt).Address)
End If

' Details pops up the properties dialog
'myEntry.Details (0)
'Debug.Print myEntry.Name & " (" & myEntry.Address & ")"
'If myEntry.DisplayType
strUser = myEntry.Name & " (" & strTempAddr & ")"
strTempAddr = ""
Select Case myEntry.DisplayType
Case olDistList, olPrivateDistList '4, 5
Debug.Print " Distribution List: " & strUser
For intCnt = 1 To myEntry.Members.Count
strTempAddr = myEntry.Members(intCnt).Address
If InStr(1, strTempAddr, "=") Then
strTempAddr = GetShortAddr(myEntry.Members(intCnt).Address)
End If
Debug.Print " Member: " & myEntry.Members(intCnt).Name _
& " (" & strTempAddr & ")"
strTempAddr = ""
Next intCnt
Case olRemoteUser '6
Debug.Print " Remote User: " & strUser

Case olUser '0
Debug.Print " User: " & strUser
Case Else
Debug.Print " Unknown " & strUser
End Select
End If
Next myEntry
End If
Next myAddressList

End Function
Public Function GetOutlook() As Outlook.Application

Dim MyOutlook As Outlook.Application ' Variable to hold reference
Dim OutlookWasNotRunning As Boolean ' Flag for final release.

On Error Resume Next ' Defer error trapping.
Set MyOutlook = GetObject(, "Outlook.Application")
If Err.Number <> 0 Then OutlookWasNotRunning = True
Err.Clear ' Clear Err object in case error occurred.

If OutlookWasNotRunning = True Then
MyOutlook.Application.Quit
End If

Set GetOutlook = MyOutlook.Application
Set MyOutlook = Nothing ' Release reference to the

' application and spreadsheet.
End Function Professional growth follows a healthy professional curiosity
 
None of both codes above has worked for me because all I want to do is display the whole list of names from the address book.
The first code is like I need add a new member.
The second code is waiting for me to enter parameter, like searching for a name.
I've worked around this code, make changes, but nothing has make my code any happy.

Thank you guys for the time you have spent. I appreciate.
 
Hi lulo,

try this:

Dim ol As Outlook.Application
Dim ns As Outlook.NameSpace
Dim ct As Outlook.MAPIFolder



Set ol = New Outlook.Application
Set ns = ol.GetNamespace(&quot;Mapi&quot;)

Set ct = ns.GetDefaultFolder(olFolderInbox)


no = ns.AddressLists.Item(1).AddressEntries.Count

For i = 1 To no
List1.AddItem ns.AddressLists.Item(1).AddressEntries.Item(i).Name
Next i

It will list all names in list1, but it takes a little while .... Adresslist no 1 is The GlobalAdressBook on my machine.

Tom
 
Thanks TomB. I appreciate, but still did not work for me

This part of code does not work:
no = ns.AddressLists.Item(1).AddressEntries.Count

Error I get is &quot;ns&quot; does support this property which is addresslists(1).AddressEntries.count

Tell me what you think. I have a reference to Outlook 8.0 is that what you have, please let me know.

Thanks a lot.


Lulo
 
I'm working with Office 2000 (OLB 9.0). You should check the NameSpace properties in the object browser. I don't know if there is something different in olb 8.0, sorry.

Tom
 
Guys, I tried MSDN help and got good one solution for
Microsoft Outlook 98..but no luck for Outlook Express 5

I wonder what the difference is ???...i think using
MAPI makes any difference....no..

if any good ideas then please let me know.

thanks guys
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top