从 Outlook 地址列表 vba 获取经理信息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15532871/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
get manager info from Outlook Address List vba
提问by maxgohan
I'm using the below code to open the Global Address List window to select a contact in the list.
我正在使用以下代码打开全局地址列表窗口以选择列表中的联系人。
For the contact that is selected, I'd like to get the Manager name as well. However, I can't seem to get it to work.
对于选定的联系人,我还想获得经理姓名。但是,我似乎无法让它发挥作用。
Any recommendations?
有什么建议吗?
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
采纳答案by maxgohan
i was able to figure it out!
我想通了!
simply had to convert the recipient object into an addressentry object and pull the manager info from there,
this can be done by using objAE.addressEntry.Manager
too!
只需将收件人对象转换为 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
回答by Dmitry Streblechenko
In case of Outlook Object Model, use AddressEntry.Manager property.
对于 Outlook 对象模型,请使用 AddressEntry.Manager 属性。
CDO 1.21 does not expose address entry's manager, but you can use Redemptionand its RDOset of objects (it offers a complete replacement of the CDO 1.21 library and can run both under Outlook and the standalone version of MAPI) - it exposes the RDOAddressEntry.Managerproperty.
CDO 1.21 不公开地址条目的管理器,但您可以使用Redemption及其RDO对象集(它完全替代了 CDO 1.21 库,并且可以在 Outlook 和独立版本的 MAPI 下运行)——它公开了RDOAddressEntry。经理财产。