由于无法使用 Outlook 中的通讯组列表来创建套用信函(无法选择这些列表),我想从通讯组列表中的联系人中读取联系人信息。
根据 API,应该可以获取 ContactItem 或使用属性访问器读取属性。两者都不起作用。一种简单的方法是只读取联系人姓名(我可以从 AddressEntry 中读取)并在 Outlook 通讯簿中搜索。但我认为这很麻烦并且可能容易出错。
请参阅下面的测试代码。GetContact() 和 GetProperty() 都不起作用。
是否有其他方法可以获取联系方式,例如名字、公司地址等?
Option Explicit
Sub test()
Dim myOlExp As Outlook.Explorer
Dim myOlSel As Outlook.Selection
Dim myOlDistList As Outlook.DistListItem
Dim nrListItems As Integer
Dim myRecipient As Outlook.Recipient
Dim myAddressEntry As Outlook.AddressEntry
Dim myContactItem As Outlook.ContactItem
Dim myPropertyAccessor As Outlook.propertyAccessor
Dim givenName As String
Set myOlExp = Application.ActiveExplorer
Set myOlSel = myOlExp.Selection
Set myOlDistList = myOlSel.Item(1)
For nrListItems = 1 To myOlDistList.MemberCount
Set myRecipient = myOlDistList.GetMember(nrListItems)
Set myAddressEntry = myRecipient.AddressEntry
' does not work
Set myContactItem = myAddressEntry.GetContact
Set myPropertyAccessor = myAddressEntry.propertyAccessor
' does also not work
givenName = myPropertyAccessor.GetProperty("urn:schemas:contacts:givenName")
Next nrListItems
End Sub