3
我有一个VBA代码来从Outlook 2013中获取整个全局地址列表,并将值Name
和置于Excel工作表中。复制包括“外部联系人”的全局地址列表联系人
问题是它只是从我的SMTP返回电子邮件/用户(我猜)。
在此图像中,我们可以从SMTP看到用户像我全身都是黑色的,并覆盖红色的外部用户。我的代码:
Sub tgr()
Dim appOL As Object
Dim oGAL As Object
Dim oContact As Object
Dim oUser As Object
Dim arrUsers(1 To 75000, 1 To 2) As String
Dim UserIndex As Long
Dim i As Long
Set appOL = CreateObject("Outlook.Application")
Set oGAL = appOL.GetNameSpace("MAPI").AddressLists("Global Address List").AddressEntries
For i = 1 To oGAL.Count
Set oContact = oGAL.Item(i)
If oContact.AddressEntryUserType = 0 Then
Set oUser = oContact.GetExchangeUser
If Len(oUser.lastname) > 0 Then
UserIndex = UserIndex + 1
arrUsers(UserIndex, 1) = oUser.Name
arrUsers(UserIndex, 2) = oUser.PrimarySMTPAddress
End If
End If
Next i
appOL.Quit
If UserIndex > 0 Then
Range("A2").Resize(UserIndex, UBound(arrUsers, 2)).Value = arrUsers
End If
Set appOL = Nothing
Set oGAL = Nothing
Set oContact = Nothing
Set oUser = Nothing
Erase arrUsers
End Sub
所以,我做错了什么?
是。你说得对。使用“oContact.AddressEntryUserType = 0或oContact.AddressEntryUserType = 5”,它返回相同的前一个结果+另外的7k个联系人。包括我的域名之外的电子邮件。但是我仍然在Outlook中看到GAL中的一些地址,并且它们不会被使用该代码返回到工作表中。 – MWsan