用于显示收件人别名的Outlook 2010 VBA代码
我的公司为每个员工分配一个ID,该ID作为他们的“别名”存储在Outlook中。我们经常使用此ID,我正在寻找一种简单的方式查看它。用于显示收件人别名的Outlook 2010 VBA代码,vba,email,outlook,alias,Vba,Email,Outlook,Alias,我的公司为每个员工分配一个ID,该ID作为他们的“别名”存储在Outlook中。我们经常使用此ID,我正在寻找一种简单的方式查看它。 现在,我在一封新电子邮件中输入收件人姓名,双击该姓名,单击“更多选项”,然后单击Outlook属性。我正在寻找一个宏,我将在新的电子邮件中输入收件人姓名,然后运行宏,该宏将弹出收件人的别名作为消息框(理想情况下将其复制到剪贴板)。我试图(但失败)自己写这篇文章 到目前为止,我的代码如下。但是,此代码给出了/o=corpexchange/ou=exchange管理组
现在,我在一封新电子邮件中输入收件人姓名,双击该姓名,单击“更多选项”,然后单击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
重新创建:
尝试使用以下方法:
您可能也会发现这篇文章很有帮助。在您的帮助下,我通过捕获收件人地址条目,将其作为新项目添加,显示别名,然后删除收件人,解决了这个问题:
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
我也遇到过类似的情况,我需要在一封电子邮件中打印出收件人的所有用户名,以便将它们导出到另一个应用程序。我的解决方案基于你的答案,下面是我的答案,以防对其他人有所帮助
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
该别名是如何存储的?您是通过编程方式(您的代码是什么?)还是通过Outlook UI执行此操作?别名存储在全局联系人信息中,与姓名等一起。如何存储?谁存储它?交换还是你的代码?在前一种情况下,您是指NT帐户名吗?别名存储在GAL中。双击收件人时,我可以通过outlook属性访问它。我正在尝试创建一个快捷方式来查看别名Eugene-我尝试过,但很难从我正在编写的打开的电子邮件中检索当前收件人(而不是宏添加收件人,然后显示详细信息)。有没有可能你可以发布代码?我试着在这上面使用代码,但无法让它工作。我想我快到了,但仍然有错误-请参阅msgbox行上当前代码编辑的原始问题。我得到的错误是对象变量或带块变量未设置。