Need Help with Code to enumerate a DL

  • Thread starter Thread starter Jeff Rush
  • Start date Start date
J

Jeff Rush

Hi All,

I have the following code and it is going horribly wrong. It is not
finding/enumerating the DL.

I could use some advice on what would be the best way to do this.
I have tried the following code and am going off track somehwere..

Any suggestions or help would be greatly appreciated.

Thx,

Jeff

CODE FOLLOWS:
----------------------------------------------------------------------------
-
Sub DLBreakout()


'Distribution List Enumeration Program.
'This Macro will do the following (1.0)
' This will read the recipients list of the current email and
' will list the members of the DL(s) in to a new email message body
' that can be sent to end users.
'

Dim MyDL As DistListItem
Dim MyRecp As Recipients


'Set variable to the (collection of) selected items in Inbox.
Set myOlSel = Application.ActiveExplorer.Selection
'Set Variable to select the default INBOX folder
Set MyFolder = Session.GetDefaultFolder(olFolderInbox)

'Set Source and Target forms
Set targetitem = MyFolder.Items.Add("ipm.note.DLList")
Set sourceitem = myOlSel(1)
Set MyRecip = sourceitem.Recipients

For x = 1 To MyRecip.Count

If MyRecip(x) = DistListItem Then

targetitem.Body.Print (MyRecip(x))

For i = 1 To MyRecip(x).Members.Count
'targetitem.Body =
MsgBox (vbCrLf & MyRecip(x).Members(i).Name)
'targetitem.Body =
MsgBox (vbCrLf & MyRecip(x).Members(i).Address)
Next

targetitem.Display

Else

MsgBox ("This ain't a DL")
targetitem.Delete

End If

Next

End Sub
 
MyRecip(x) always returns a Recipient object, not a DistListItem. You can use the Recipient.AddressEntry.DisplayType property to determine whether it's a normal recipient or an Exchange DL. If it is a DL, then you can use Recipient.AddressEntry.Members to get the individual members of the DL.

Note that you will never see an Outlook personal distribution list in a received message, since Outlook expands all PDLs when the item is sent.

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 
Thank you Sue!!

I appreciate your time and help!! Roberba was right.. YOU ROCK!!


MyRecip(x) always returns a Recipient object, not a DistListItem. You can
use the Recipient.AddressEntry.DisplayType property to determine whether
it's a normal recipient or an Exchange DL. If it is a DL, then you can use
Recipient.AddressEntry.Members to get the individual members of the DL.

Note that you will never see an Outlook personal distribution list in a
received message, since Outlook expands all PDLs when the item is sent.

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 
Back
Top