View Full Version : Continued: Display OutLook Contacts In word
Annodomini2
02-07-2006, 05:45 AM
I found the thread listed previously and solved to obtain contact information to be displayed in Word.
(Don't know how to add the link sorry).
Anyway this function provided the ability to extract the contacts from the personal address book.
I was wondering is it possible to extract the contact information from a specific distribution list?
Killian
02-07-2006, 06:12 AM
I think you're talking about this (http://www.vbaexpress.com/forum/showthread.php?t=430) thread (?)
Annodomini2
02-07-2006, 06:18 AM
That's the one! :)
Killian
02-07-2006, 06:44 AM
OK, I've looked into it a little more...
Getting the contact info from a distribution list can be done like thisDim myDistList As DistListItem
Set myNamespace = GetNamespace("MAPI")
Set myFolder = myNamespace.GetDefaultFolder(olFolderContacts)
Set myDistList = myFolder.Items("testdistlist")
For i = 1 To myDistList.MemberCount
Debug.Print myDistList.GetMember(i).Address
Next
Annodomini2
02-07-2006, 07:05 AM
What type are you using for myFolder? I saw the 'Folders' type but its resulting in an error.
Annodomini2
02-07-2006, 08:39 AM
sorry got myNameSpace wrong its named differently in mine
Killian
02-07-2006, 09:19 AM
Sorry, yes, here are all my declarationsDim myDistList As DistListItem
Dim myNamespace As NameSpace
Dim myFolder As MAPIFolder
Dim i As Long
Annodomini2
02-08-2006, 02:37 AM
Thanks for that, got it working so far
How could I change the contacts folder for the global one?
Killian
02-08-2006, 04:09 AM
Use GetDefaultFolder will return one of the following:
olFolderCalendar, olFolderContacts, olFolderDeletedItems, olFolderDrafts, olFolderInbox, olFolderJournal, olFolderNotes, olFolderOutbox, olFolderSentMail, olFolderTasks, olPublicFoldersAllPublicFolders, and olFolderJunk
Otherwise, to navigate to a custom folder, you drill down thru the tree structure:Set TargetFolder = ns.Folders.Item( _
"Personal Folders").Folders.Item("Temp")(where ns is the MAPI NameSpace)
If you're trying to map to a LAN global contacts list, you'll need to find how it's mapped to your account. On large scale exchange server deployments, this is usually done through Public Folders.
Annodomini2
02-08-2006, 06:42 AM
Don't quite get you on this one, it is for LAN, large scale.
Therefore would the code be:
Set TargetFolder = ns.Folders.Item( _
"Public Folders").Folders.Item("Temp")
If this is the case, what is the purpose of .Folders.Item("Temp") ?
Killian
02-08-2006, 09:29 AM
It's just and example...
If the outlook folder you want to target (for whatever purpose) is:
Public Folders>Invoices>Pending>Jan06
then you "navigate" thru the folders with the syntax:Set TargetFolder = ns.Folders.Item( _
"Public Folders").Folders.Item( _
"Invoices").Folders.Item( _
"Pending").Folders.Item("Jan06")
Normally, GetDefaultFolder (olFolderContacts) would get you to the global contacts list.
If that's not the case, you might want to speak to one of your Exchange server admins to find out it's location
Annodomini2
02-09-2006, 05:51 AM
Ahh, I think I understand how this thing is working, its using the local Outlook folders to obtain the information. (penny's dropped! :D)
How would I access the Address book directly?
Annodomini2
02-09-2006, 07:25 AM
Using AddressLists?
Killian
02-09-2006, 09:43 AM
Yes, that sounds about right...
Here's some code that lists the names of all the address list (books) you can access in the Immediate wondow (Ctrl+G in the VBE)Dim ns As NameSpace
Dim myList As AddressList
Set ns = GetNamespace("MAPI")
For Each myList In ns.AddressLists
Debug.Print myList.Name
Next
Annodomini2
02-10-2006, 01:38 AM
Yes, that sounds about right...
Here's some code that lists the names of all the address list (books) you can access in the Immediate wondow (Ctrl+G in the VBE)Dim ns As NameSpace
Dim myList As AddressList
Set ns = GetNamespace("MAPI")
For Each myList In ns.AddressLists
Debug.Print myList.Name
Next
Yep had something similar working to this yesterday:
Dim oNspc As Outlook.NameSpace
Dim oNList As AddressList
Dim oNAddress As AddressEntry
Set oApp = CreateObject("Outlook.Application")
Set oNspc = oApp.GetNamespace("MAPI")
Set oNList = oNspc.AddressLists(frmSelectList.GroupList)
Set oNAddress = oNList.AddressEntries.Item(frmSelectList.DistributionList)
'Make sure the Contacts folder contains entries
j = 0
If oNAddress.Members.Count > 0 Then
For i = 1 To oNAddress.Members.Count
With cboRecipient
If oNAddress.Members.Item(i).Class <> olDistributionList Then
.AddItem oNAddress.Members.Item(i).Name
.Column(1, i - 1) = oNAddress.Members.Item(i).Address
Else
j = j + 1
End If
End With
Next i
End If
This is using information from a previous form to populate a combobox with the Name and Email information.
However, different to the previous example operation these members of oNAddress (oNAddress is a Group/Distribution list) only the name is stored, all the classes are identical and Address property contains what appears to be a link to the email address.
Now do you know of methods to complete these links and access the information? Or would I have to perform a 2nd lookup operation for the Name of the Group/Individual and create a distribution list/contact using the results of that lookup?
This is because I would like to populate the entire combo box, before allowing the user to continue.
Annodomini2
02-14-2006, 09:37 AM
Bump and a more detailed question:
Here is my code:
Dim oNspc As Outlook.NameSpace
Dim i As Integer, j As Integer
Dim oNList As AddressList
Dim oNAddress As AddressEntry
Dim DistList As DistListItem
Dim type1 As String
Dim oFolder As Folders
If Not DisplayStatusBar Then
DisplayStatusBar = True
End If
StatusBar = "Please Wait Populating Recipients..."
Set oApp = CreateObject("Outlook.Application")
Set oNspc = oApp.GetNamespace("MAPI")
Set oNList = oNspc.AddressLists(frmSelectList.GroupList)
Set oNAddress = oNList.AddressEntries.Item(frmSelectList.DistributionListName)
'Make sure the Contacts folder contains entries
j = 0
If oNAddress.Members.Count > 0 Then
For i = 1 To oNAddress.Members.Count
With cboRecipient
If oNAddress.Members.Item(i).DisplayType = olUser Then
.AddItem oNAddress.Members.Item(i).Name
.Column(1, i - 1) = oNAddress.Members.Item(i).Address
Else
j = j + 1
End If
End With
Next i
End If
I have got the system to list the contents a defined distribution list, selected from the previous form.
Now oNAddress.Members.Item(i).Name returns the users name, which is what I am looking for. However, oNAddress.Members.Item(i).Address returns some form of link to the email address or possibly other data and not the data I am looking for.
Is it possible to perform some operation which will return this data?
This is the only remaining issue with this piece of code (ok it's not optimal! http://vbaexpress.com/forum/images/smilies/wink.gif)
I have attached the file, this 'should' be generic so it 'should' work on any word 2000 system, later versions I am unsure as it is untested.
TIA
Anno
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.