The following macro in Outlook will list all the distribution lists
containing the name you enter into the dialog box in a Word document
Sub ListNames()
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Dim myNameSpace As Outlook.NameSpace
Dim myFolder As Outlook.Folder
Dim myDistList As Outlook.DistListItem
Dim myFolderItems As Outlook.Items
Dim myListMember As String
Dim sList As String
Dim x As Integer
Dim y As Integer
Dim iCount As Integer
myListMember = InputBox("Enter name of list member to be found", _
"Find name in Distribution Lists")
Set myNameSpace = Application.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderContacts)
Set myFolderItems = myFolder.Items
iCount = myFolderItems.Count
sList = ""
For x = 1 To iCount
If TypeName(myFolderItems.Item(x)) = "DistListItem" Then
Set myDistList = myFolderItems.Item(x)
For y = 1 To myDistList.MemberCount
If InStr(1, myDistList.GetMember(y).Name, myListMember) Then
'MsgBox myDistList.GetMember(y).Name & _
" is a member of " & myDistList.DLName, _
vbInformation, "Distribution List"
If sList = "" Then
sList = sList & myDistList.GetMember(y).Name _
& vbTab & myDistList.DLName
Else
sList = sList & vbCr & myDistList.GetMember(y).Name _
& vbTab & myDistList.DLName
End If
End If
Next y
End If
Next x
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err Then
Set wdApp = CreateObject("Word.Application")
End If
Set wdDoc = wdApp.Documents.Add
wdApp.Visible = True
wdApp.Activate
With wdDoc.Range
.InsertAfter sList
.ParagraphFormat.TabStops.ClearAll
.ParagraphFormat.TabStops.Add Position:=InchesToPoints(4), _
Alignment:=wdAlignTabLeft, Leader:=wdTabLeaderSpaces
End With
Set wdDoc = Nothing
Set wdApp = Nothing
End Sub
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site
www.gmayor.com
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>