1

我正在使用以下代码打开“全局地址列表”窗口以选择列表中的联系人。

对于选择的联系人,我也想获取经理姓名。但是,我似乎无法让它工作。

有什么建议吗?

Private Sub accountManagerName_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    Dim CDOSession, cdoAddressBook, olkRecipients, objAE

    On Error Resume Next
    Set CDOSession = CreateObject("MAPI.Session")
'   Change the name of your Outlook profile as needed.
    CDOSession.Logon "", "", False, False
    Set olkRecipients = CDOSession.AddressBook(, "Global Address List", 0, False)
    For Each objAE In olkRecipients
        accountManagerName.Text = objAE.name
        'ccManager.Caption = objAE.Manager.name
    Next
    Set olkRecipients = Nothing
    CDOSession.Logoff
    Set CDOSession = Nothing
End Sub
4

2 回答 2

0

如果是 Outlook 对象模型,请使用 AddressEntry.Manager 属性。

CDO 1.21 不公开地址条目的管理器,但您可以使用Redemption及其RDO对象集(它提供了 CDO 1.21 库的完全替代,并且可以在 Outlook 和 MAPI 的独立版本下运行) - 它公开了RDOAddressEntry。经理财产。

于 2013-03-21T06:37:57.610 回答
0

我能够弄清楚!

只需将接收者对象转换为地址条目对象并从那里提取经理信息,这也可以通过使用来完成objAE.addressEntry.Manager

Private Sub accountManagerName_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)

    On Error Resume Next
    Set CDOSession = CreateObject("MAPI.Session")
'   Change the name of your Outlook profile as needed.
    CDOSession.Logon "", "", False, False
        If Err.Number <> 0 Then MsgBox "Please ensure you have Outlook open.", , "ERROR"
    Set olkRecipients = CDOSession.AddressBook(, "Select Account Manager", 0, False)

    For Each objAE In olkRecipients
        accountManagerName.Text = objAE.name
        AMfullName = objAE.name

        'convert Recipient object to AddressEntry object using the recipient ID
        Set objAE2 = CDOSession.GetAddressEntry(objAE.ID)

        AMfirstName = objAE2.fields(18)
        AMlastName = objAE2.fields(22)
        AMmanagerName = objAE2.Manager

'        Debug.Print AMfirstName
'        Debug.Print AMlastName
'        Debug.Print AMmanagerName
    Next

    ccAMmanager.Caption = AMmanagerName
    ccUserManager.Caption = getName("mgrname")
    ccAMmanager.Activate

    Set olkRecipients = Nothing
    CDOSession.Logoff
    Set CDOSession = Nothing


End Sub
于 2013-03-21T21:29:16.427 回答