T
Tony Zappal
Hi All,
Im using the following macro to try and list the members of a contact list
from Outlook 2000-(cant remember where i found it):
Sub ListMembers()
Dim olApp As New Outlook.Application
Dim olNS As Outlook.NameSpace
Dim ctFolder As Outlook.MAPIFolder
Dim myDistList As Outlook.DistListItem
Dim ctFolderItems As Outlook.Items
Dim myRcpnt As Outlook.Recipient
Dim iterateCtItems As Integer
Dim iterateMembers As Integer
Dim countCtItems As Integer
Dim countMembers As Integer
Dim R As Integer
Dim criteria As String
Dim itm As Object
Set olNS = olApp.GetNamespace("MAPI")
Set ctFolder = olNS.GetDefaultFolder(olFolderContacts)
Set ctFolderItems = ctFolder.Items
countCtItems = ctFolderItems.Count
R = 1
For iterateCtItems = 1 To countCtItems
If TypeName(ctFolderItems.Item(iterateCtItems)) = "DistListItem" Then
Set myDistList = ctFolderItems.Item(iterateCtItems)
If myDistList.DLName = "DL Monthly Finance Reports" Then
countMembers = myDistList.MemberCount
For iterateMembers = 1 To countMembers
Set myRcpnt =
olApp.Session.CreateRecipient(myDistList.GetMember(iterateMembers).Address)
myRcpnt.Resolve
If myRcpnt.Resolved = True Then
criteria = "[Email1Address] = " & myRcpnt.Address
Set itm = ctFolderItems.Find(criteria)
Sheets("Sheet1").Cells(R, 1).Value = itm.FullName
R = R + 1
End If
Next iterateMembers
End If
End If
Next iterateCtItems
Set olNS = Nothing
Set olApp = Nothing
End Sub
When i run it, i get the following error:
Run-time error'-1871577079 (90720009)': Condition is not valid.
Looking at the debug info, it has found the distribution list and is reading
the first contact, but is failing bring across the name of the contact.
It's falling over on the "Set itm = ctFolderItems.Find(criteria)" line.
Can someone please help.
Thanks.
Tony.
Im using the following macro to try and list the members of a contact list
from Outlook 2000-(cant remember where i found it):
Sub ListMembers()
Dim olApp As New Outlook.Application
Dim olNS As Outlook.NameSpace
Dim ctFolder As Outlook.MAPIFolder
Dim myDistList As Outlook.DistListItem
Dim ctFolderItems As Outlook.Items
Dim myRcpnt As Outlook.Recipient
Dim iterateCtItems As Integer
Dim iterateMembers As Integer
Dim countCtItems As Integer
Dim countMembers As Integer
Dim R As Integer
Dim criteria As String
Dim itm As Object
Set olNS = olApp.GetNamespace("MAPI")
Set ctFolder = olNS.GetDefaultFolder(olFolderContacts)
Set ctFolderItems = ctFolder.Items
countCtItems = ctFolderItems.Count
R = 1
For iterateCtItems = 1 To countCtItems
If TypeName(ctFolderItems.Item(iterateCtItems)) = "DistListItem" Then
Set myDistList = ctFolderItems.Item(iterateCtItems)
If myDistList.DLName = "DL Monthly Finance Reports" Then
countMembers = myDistList.MemberCount
For iterateMembers = 1 To countMembers
Set myRcpnt =
olApp.Session.CreateRecipient(myDistList.GetMember(iterateMembers).Address)
myRcpnt.Resolve
If myRcpnt.Resolved = True Then
criteria = "[Email1Address] = " & myRcpnt.Address
Set itm = ctFolderItems.Find(criteria)
Sheets("Sheet1").Cells(R, 1).Value = itm.FullName
R = R + 1
End If
Next iterateMembers
End If
End If
Next iterateCtItems
Set olNS = Nothing
Set olApp = Nothing
End Sub
When i run it, i get the following error:
Run-time error'-1871577079 (90720009)': Condition is not valid.
Looking at the debug info, it has found the distribution list and is reading
the first contact, but is failing bring across the name of the contact.
It's falling over on the "Set itm = ctFolderItems.Find(criteria)" line.
Can someone please help.
Thanks.
Tony.