【问题标题】:Outlook 2010 VBA code to show alias of recipientOutlook 2010 VBA 代码显示收件人的别名
【发布时间】:2020-06-23 15:06:16
【问题描述】:

我的公司为每位员工分配了一个 ID,该 ID 作为他们的“别名”存储在 Outlook 中。我们经常使用这个 ID,我正在寻找一种简单的方法来查看它。
现在我在新电子邮件中输入收件人姓名,双击名称,单击更多选项,然后单击 Outlook 属性。我正在寻找一个可以在新电子邮件中输入收件人姓名的宏,然后运行该宏,该宏只会将收件人的别名作为消息框弹出(最好将其复制到剪贴板)。我自己尝试过(但失败了)。

我到目前为止的代码如下。但是,此代码给出 /o=corpexchange/ou=exchange 管理组.....

我试图让它返回别名

 Sub ReadRecpDetail2()



Dim myOlApp As Outlook.Application

Dim myItem As Outlook.MailItem

Dim myRecipient As Outlook.recipient

 Dim recipient As Outlook.recipient


Set myOlApp = GetObject(, "Outlook.Application")

Set myItem = myOlApp.ActiveInspector.CurrentItem


For Each recipient In myItem.Recipients
  recipient.Resolve
  MsgBox recipient.AddressEntry

Next recipient
    End Sub

重新创建:

  1. 打开新的 Outlook 电子邮件
  2. 输入电子邮件地址并解析
  3. 运行宏

【问题讨论】:

  • 该别名究竟是如何存储的?您是通过编程方式(您的代码是什么?)还是通过 Outlook 用户界面执行此操作?
  • 别名与名字和姓氏等一起存储在全局联系信息中。
  • 如何存储?谁存储它?交换或您的代码?在前一种情况下,您只是指 NT 帐户名称吗?
  • 别名存储在 GAL 中。双击收件人时,我可以通过 Outlook 属性访问它。我正在尝试创建一个查看别名的快捷方式

标签: vba email outlook alias


【解决方案1】:

尝试使用以下方法:

  1. 使用命名空间类的CreateRecipient 方法创建一个收件人对象。
  2. 调用 Recipient 类的 Resolve 方法以根据通讯簿解析 Recipient 对象。
  3. 获取AddressEntry属性值,返回解析接收者对应的AddressEntry对象。
  4. 调用AddressEntry类的GetExchangeUser方法,如果AddressEntry属于全局地址列表(GAL)等Exchange AddressList对象,对应一个Exchange用户,则返回一个ExchangeUser对象,代表AddressEntry。李>
  5. ExchangeUser 类的Alias 属性返回一个表示ExchangeUser 别名的字符串。

Getting Started with VBA in Outlook 2010 文章可能对您也有帮助。

【讨论】:

  • 谢谢尤金 - 我试过了,但很难从我正在写的打开的电子邮件中检索当前收件人(而不是宏添加收件人然后显示详细信息)。你有机会发布代码吗?
  • 我尝试使用Site 上的代码,但无法正常工作
  • 我想我快到了,但仍然出现错误 - 请使用当前代码查看已编辑的原始问题
  • 在 msgbox 行上,我收到未设置对象变量或块变量的错误
【解决方案2】:

在您的帮助下,我能够通过捕获收件人地址条目、将其添加为新项目、显示别名然后删除收件人来解决此问题:

Sub ReadRecpDetail()
Dim myOlApp As Outlook.Application
Dim myItem As Outlook.mailItem
Dim myRecipient As Outlook.recipient
Dim recipient As Outlook.recipient
Dim SMTPaddress As String
Dim entry As Outlook.AddressEntry
Dim entrystring As String
Dim Copytoclipboard As New DataObject

Set myOlApp = GetObject(, "Outlook.Application")
Set myItem = myOlApp.ActiveInspector.CurrentItem
Set recipient = myItem.Recipients.Item(1)
Set myRecipient = myItem.Recipients.Add(recipient.AddressEntry)

myRecipient.Resolve
entrystring = myRecipient.AddressEntry.GetExchangeUser.Alias
MsgBox (entrystring)
Copytoclipboard.SetText entrystring
Copytoclipboard.PutInClipboard
myRecipient.Delete

End Sub

【讨论】:

    【解决方案3】:

    我遇到过类似的情况,我需要在电子邮件中打印出收件人的所有用户名,以便将它们导出到另一个应用程序。我的解决方案基于您的回答,以防它对其他人有所帮助。

    Sub PrintRecipientAliases()
    
        Dim myOlApp As Outlook.Application
        Dim myItem As Outlook.MailItem
        Dim recipient As Outlook.recipient
    
        Set myOlApp = GetObject(, "Outlook.Application")
        Set myItem = myOlApp.ActiveInspector.CurrentItem
    
        For Each recipient In myItem.Recipients
            With recipient
                Debug.Print recipient.AddressEntry.GetExchangeUser.Alias
            End With
        Next
    
    End Sub
    

    【讨论】:

      猜你喜欢
      • 2015-05-08
      • 2012-03-18
      • 1970-01-01
      • 2017-06-27
      • 1970-01-01
      • 2015-05-11
      • 1970-01-01
      • 1970-01-01
      • 2017-07-09
      相关资源
      最近更新 更多