PDA

View Full Version : Updating Distribution Lists



mevans
03-05-2005, 03:32 AM
I'm pretty good with Excel VBA but don't know a lot about Outlook.

I would like to write a simple search/replace tool which would search through all the Distribution Lists in my Personal Address Book (OL2000), look for a particular name, and either remove the name from the list or change it to another name.

Anyone have any ideas how I might do this?

Matthew Evans
Canada

brettdj
03-05-2005, 05:37 AM
Hi Matthew,

Attached are two approaches below for accessing the members of your distributions list from VBA (I've assumed Excel) to help get you started. The first uses the Outlook object, the second uses Microsoft CDO 1.21. They dump the distribution lists into Excel.

It is possible to remove or add members, see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbaol10/html/olmthAddMember.asp

Cheers

Dave


Sub ContactItems()
'Set a ref to the Outlook Object
Dim objApp As Outlook.Application, objNS As Outlook.Namespace
Dim objFolder As Outlook.MAPIFolder
Dim objDistLIst 'As Outlook.DistListItem
Dim v As Long, i As Long
Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")
Set objFolder = objNS.GetDefaultFolder(olFolderContacts)

For Each objDistLIst In objFolder.Items
'skip contacts
If TypeName(objDistLIst) = "DistListItem" Then
v = v + 1
Cells(1, v) = objDistLIst
For i = 1 To objDistLIst.MemberCount
Cells(i + 1, v) = objDistLIst.GetMember(i).AddressEntry
Next
End If
Next

Set objFolder = Nothing
Set objApp = Nothing
End Sub

Sub Approach2()
'Set a ref to CDO 1.21
Dim objSession As MAPI.Session, oAddressList As MAPI.AddressList, oEntry As MAPI.AddressEntry
Dim i As Long
Dim Mem As MAPI.AddressEntry
Set objSession = New MAPI.Session
With objSession
.Logon , , False, False
Set oAddressList = .AddressLists("Contacts")
On Error Resume Next
For Each oEntry In oAddressList.AddressEntries
If oEntry.DisplayType = olPrivateDistList Then
v = v + 1
i = 1
Cells(i, v * 2 - 1) = oEntry.Name & " contact"
Cells(i, v * 2) = oEntry.Name & " address"
For Each Mem In oEntry.Members
i = i + 1
Cells(i, v * 2 - 1) = Mem.Name
Cells(i, v * 2) = Mem.Address
Next
End If
Next
End With
Set oAddressList = Nothing
Set objSession = Nothing
End Sub

Emily
04-30-2005, 11:22 PM
With refer to approach 1

There is a pop up window as attached (Window 2000 + Outlook 2003). How to reply automatically?

Thanks
Emily

MOS MASTER
05-01-2005, 11:24 AM
Hi Emily, :D

Since Office 2000 (I think SP3) there is a new Security feature in Office that makes it nearly impossible for VBA programs to send mail or adjust user enviroment of Outlook without you getting this message.

The easy way to get rid is by Installing the program ClickYes witch will press the buttons for you.

All the alternatives are listed here:http://www.outlookcode.com/d/sec.htm

Enjoy! :whistle:

Emily
05-01-2005, 07:28 PM
Thanks

MOS MASTER
05-02-2005, 10:43 AM
You're Welcome! :beerchug: