获取联系人组电子邮件地址

时间:2016-10-27 07:22:15

标签: excel-vba email outlook vba excel

我有这个代码可以获取组织列表中的电子邮件地址和名称。

Sub Email_Extract()
Dim colAL As Outlook.AddressLists
Dim oAL As Outlook.AddressList
Dim colAE As Outlook.AddressEntries
Dim oAE As Outlook.AddressEntry
Dim oExUser As Outlook.ExchangeUser
Dim n As Long

Set colAL = Outlook.Application.Session.AddressLists

For Each oAL In colAL

If oAL.AddressListType = olExchangeGlobalAddressList Then

Set colAE = oAL.AddressEntries
    n = 2
        For Each oAE In colAE

            If oAE.AddressEntryUserType = olExchangeUserAddressEntry Then

                Set oExUser = oAE.GetExchangeUser

                ThisWorkbook.Sheets("Sheet1").Cells(n, 1).Value = oExUser.Name 'User Name
                ThisWorkbook.Sheets("Sheet1").Cells(n, 2).Value = oExUser.PrimarySmtpAddress 'SMTP address
                 n = n + 1
                   Cells(n, 1).Activate
'if a contact group
            ElseIf oAE.AddressEntryUserType = olExchangeDistributionListAddressEntry Then
                ThisWorkbook.Sheets("Sheet1").Cells(n, 1).Value = oAE.Name
                ThisWorkbook.Sheets("Sheet1").Cells(n, 2).Value = oAE.AddressEntryUserType
                ThisWorkbook.Sheets("Sheet1").Cells(n, 3).Value = oAE.Address
                ThisWorkbook.Sheets("Sheet1").Cells(n, 3).Value = oAE.Name
            n = n + 1
            Cells(n, 1).Activate
           End If
       Next
   End If
Next

我已经可以获得联系人组的名称。但我现在的问题是我无法联系到联络小组。电子邮件地址,例如sample.sample@mail.com。有什么帮助吗?

1 个答案:

答案 0 :(得分:0)

循环遍历从AddressEntry.Members集合返回的地址条目。

相关问题