This Microsoft Visual Basic/Visual Basic for Applications example steps through the default Contacts folder, and if it finds a distribution list with more than 20 members it displays the item.
Dim myOlApp As New Outlook.Application
Dim myOlFolder As Outlook.MAPIFolder
Dim myOlItems As Outlook.Items
Dim myOlDistList As Outlook.DistListItem
Set myOlFolder = myOlApp.GetNamespace("MAPI").GetDefaultFolder(olFolderContacts)
Set myOlItems = myOlFolder.Items
For x = 1 To myOlItems.Count
If TypeName(myOlItems.Item(x)) = "DistListItem" Then
Set myOlDistList = myOlItems.Item(x)
If myOlDistList.MemberCount > 20 Then
MsgBox myOlDistList.DLName & " has more than 20 members."
myOlDistList.Display
End If
End If
Next x
If you use VBScript, you do not create the Application object, and you cannot use named constants. This example shows how to perform the same task using VBScript.
Set myOlFolder = _
Application.GetNamespace("MAPI").GetDefaultFolder(10)
Set myOlItems = myOlFolder.Items
For x = 1 To myOlItems.Count
If TypeName(myOlItems.Item(x)) = "DistListItem" Then
Set myOlDistList = myOlItems.Item(x)
If myOlDistList.MemberCount > 20 Then
MsgBox myOlDistList.DLName & _
" has more than 20 members."
myOlDistList.Display
End If
End If
Next