get Manager from Outlook Contacts using VBA

谁都会走 提交于 2019-12-08 02:17:02

问题


I have the below code that retrieves the Global Address List from Outlook then creates an array with the name and the department.

I'd like to get the users manager - but I can't find it in the list of properties and oUser.GetExchangeUserManager doesn't work

    Dim appOL As Outlook.Application ' Object
    Dim oGAL As Outlook.AddressEntries ' .NameSpace  Object
    Dim oContact As Outlook.AddressEntry ' Object
    Dim oUser As ExchangeUser ' Object
    Dim arrUsers(1 To 65000, 1 To 4) As String
    Dim UserIndex As Long
    Dim i As Long

    Set appOL = New Outlook.Application ' 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.Department
                arrUsers(UserIndex, 3) = oUser.JobTitle ' Blank
                'arrUsers(UserIndex, 4) = oUser.GetExchangeUserManager  ' ERROR         
            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

any thoughts on how to get the manager info?


回答1:


Use AddressEntry.Manager - it will return another AddressEntry object that represents the manager. Be prepared to handle Nulls.



来源:https://stackoverflow.com/questions/20519230/get-manager-from-outlook-contacts-using-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!