簡體   English   中英

在Outlook中導入聯系人/ Nab組

[英]Import Contact/Nab Groups in outlook

在這種情況下,我必須導入組織內部Outlook中的所有聯系人,包括nab組或組聯系人。 我有在某個地方找到的這段代碼,但這不包括聯系人組。 這僅導入聯系人。

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
StartTime = Timer

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
           End if
      Next
  Endif
Next
End sub

請注意,其運行時間取決於組織的電子郵件地址。 我在這里找到了一些信息但是這個想法有點懸而未決。 無論如何,我可以在此過程中包括聯系人組嗎? 請幫忙。 謝謝。

這暗示着還有其他類型,因此不限於一種類型。

If oAE.AddressEntryUserType = olExchangeUserAddressEntry Then

這演示了如何處理其他類型。 (演示代碼是為Outlook而不是Excel設置的。)

Option Explicit

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

Set colAL = Session.AddressLists

For Each oAL In colAL

    If oAL.AddressListType = olExchangeGlobalAddressList Then

        Set colAE = oAL.AddressEntries

        For Each oAE In colAE

            If oAE.AddressEntryUserType = olExchangeUserAddressEntry Then
                'Set oExUser = oAE.GetExchangeUser
                'Debug.Print oExUser.Name

            ElseIf oAE.AddressEntryUserType = olExchangeDistributionListAddressEntry Then
                ' https://msdn.microsoft.com/en-us/library/office/ff868214.aspx
                ' An address entry that is an Exchange distribution list.
                Debug.Print vbCr & "Exchange distribution list - AddressEntryUserType: " & oAE.AddressEntryUserType
                Debug.Print "  " & oAE.Name

            Else
                'Debug.Print vbCr & "? - AddressEntryUserType: " & oAE.AddressEntryUserType
                'Debug.Print "  " & oAE.Name

            End If
        Next
    End If
Next

End Sub

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM