title: Retrieve members of nested Outlook distribution list with VBA
body: <p>I'd like to retrieve the members of an Outlook distribution list. Most of them just contain contacts. However, strangely, I found some of these to contain themselves. When double-clicking on these in Outlook, I can see their members, but I couldn't figure out a possibility to access these in VBA. </p>
  
  <p>The following code prints all members from all distribution lists in my local contact list, but, as I mentioned, for some distribution lists, it will only print themselves.</p>
  
  <p>A sample result would look like this:
  PDL - sampleList
  PDL - sampleList -- sampleList@company.com</p>
  
  <pre><code>Sub test()
  
  Dim objDistList As DistListItem
  
  Const olFolderContacts = 10
  
  Set objOutlook = CreateObject("Outlook.Application")
  Set objNamespace = objOutlook.GetNamespace("MAPI")
  
  Set colContacts = objNamespace.GetDefaultFolder(olFolderContacts).Items
  intCount = colContacts.Count
  
  For i = 1 To intCount
      If TypeName(colContacts.Item(i)) = "DistListItem" Then
          Set objDistList = colContacts.Item(i)
          Debug.Print objDistList.DLName
          For j = 1 To objDistList.MemberCount
      Debug.Print objDistList.GetMember(j).Name &amp; " -- " &amp; objDistList.GetMember(j).Address
          Next
      End If
  Next
  
  End Sub
  </code></pre>