简体   繁体   English

如果关联名称包含字符串,如何从 Outlook VBA 的全局地址列表中提取 Email 地址

[英]How to Pull Email Address from Global Address List in Outlook VBA if the Associated Name contains String

First time poster.第一次海报。 I am trying to pull the email address from an entry in the Global Address List in Outlook to refer to within my VBA code, I need to input a project code.我正在尝试从 Outlook 的全局地址列表中的条目中提取 email 地址,以便在我的 VBA 代码中引用,我需要输入项目代码。 whereby the code will need to look through the GAL and find the entry where the project code is found in the name, When it finds this.从而代码将需要查看 GAL 并找到项目代码在名称中的条目,当它找到这个时。 I need it to return the associated email address (PrimarySMTPAddress), If no.我需要它返回关联的 email 地址(PrimarySMTPAddress),如果没有。 I need it to say 'Project code not found'.我需要它说“找不到项目代码”。

I am very new to VBA, so I can't put this thought into code.我对 VBA 很陌生,所以我不能把这个想法变成代码。 Any help is appreciated.任何帮助表示赞赏。

Thanks.谢谢。

Use the CreateRecipient method of the Namespace class which creates a Recipient object.使用Namespace class 的CreateRecipient方法创建一个Recipient object。 This method is most commonly used to create a Recipient object for use with the GetSharedDefaultFolder method, for example, to open a delegator's folder.此方法最常用于创建与GetSharedDefaultFolder方法一起使用的Recipient object,例如,打开委托人的文件夹。 It can also be used to verify a given name against an address book.它还可用于根据地址簿验证给定名称。

Sub ResolveName()
 Dim myNamespace As Outlook.NameSpace
 Dim myRecipient As Outlook.Recipient
 Dim CalendarFolder As Outlook.Folder
 Set myNamespace = Application.GetNamespace("MAPI")
 Set myRecipient = myNamespace.CreateRecipient("Project Name 0001") 
 
 myRecipient.Resolve 
 
 If myRecipient.Resolved Then 
   Call ShowCalendar(myNamespace, myRecipient)
 End If 
End Sub 
 
Sub ShowCalendar(myNamespace, myRecipient) 
 Dim CalendarFolder As Folder 
 Set CalendarFolder = myNamespace.GetSharedDefaultFolder(myRecipient, olFolderCalendar) 
 CalendarFolder.Display 
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM