首页 > 解决方案 > 从电子邮件地址获取经理

问题描述

我正在尝试获取特定人员的“经理”(并希望之后迭代目标列表)。如何为特定的电子邮件地址而不是全局地址列表执行此操作?

Dim appOL As Outlook.Application ' Object
Dim oGAL As Outlook.AddressEntries ' .NameSpace  Object
Dim oContact As Outlook.AddressEntry ' Object
Dim oUser As ExchangeUser ' Object

Set appOL = New Outlook.Application ' CreateObject("Outlook.Application")
Set oGAL = appOL.GetNameSpace("MAPI").AddressLists("Global Address List").AddressEntries("first.last@email.com")
oContact = oGAL.Item(1)
MsgBox oContact.Manager

标签: vbaoutlook

解决方案


替换行

Set oGAL = appOL.GetNameSpace("MAPI").AddressLists("Global Address List").AddressEntries("first.last@email.com")
oContact = oGAL.Item(1)

使用以下内容(假设您正在使用 Outlook 中的选定邮件):

if appOL.ActiveExplorer.Selection.Count > 0 Then
  set msg = appOL.ActiveExplorer.Selection(1)
  set sender = msg.Sender
  if Not (sender is null) Then
    set manager = sender.Manager
  End If
End If

如果您使用一次性名称,请使用类似

set recip = appOL.Session.CreateRecipient("The name to resolve")
if recip.Resolve Then
  set manager = recip.AddressEntry.Manager
End If

推荐阅读