【发布时间】:2020-06-26 06:54:23
【问题描述】:
我想检索 Outlook 通讯组列表的成员。他们中的大多数只包含联系人。然而,奇怪的是,我发现其中一些可以控制自己。在 Outlook 中双击它们时,我可以看到它们的成员,但我想不出在 VBA 中访问它们的可能性。
以下代码打印本地联系人列表中所有通讯组列表中的所有成员,但是,正如我所提到的,对于某些通讯组列表,它只会打印自己。
示例结果如下所示: PDL - 样本列表 PDL - sampleList -- sampleList@company.com
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 & " -- " & objDistList.GetMember(j).Address
Next
End If
Next
End Sub
【问题讨论】: