从Outlook地址列表vba获取pipe理器信息

我正在使用下面的代码来打开全局地址列表窗口来select列表中的联系人。

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

任何build议?

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 

在Outlook对象模型的情况下,使用AddressEntry.Manager属性。

CDO 1.21不公开地址条目的pipe理器,但可以使用Redemption及其RDO对象集(它提供了CDO 1.21库的完整替代品,并且可以在Outlook和独立版本的MAPI下运行),它暴露了RDOAddressEntry。经理属性。

我能弄明白了!

只需要将收件人对象转换为一个addressentry对象,并从那里拉经理信息,这也可以通过使用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