确保分发列表中的联系人显示名称和电子邮件地址

时间:2010-05-05 14:06:56

标签: vba outlook outlook-vba distribution-list

如何确保我添加到Outlook通讯组列表中的联系人同时显示名称和电子邮件地址?这些联系人可能不存在于任何其他地址簿中,只存在于通讯组列表中。目前,它们只显示为电子邮件地址(在两个列中)。

alt text http://img52.imageshack.us/img52/1804/tempgg.jpg

这大致是我们正在使用的VBA:

    Do Until RS.EOF

        //here's where we want to inject RS!FirstName, RS!Surname etc
        objRecipients.Add RS!Email
        objRecipients.Resolve

        RS.MoveNext
    Loop


    Set objDistList = contactsFolder.Items.Add("IPM.DistList")
    objDistList.DLName = "Whatever"

    objDistList.AddMembers objRecipients
    objDistList.Save

    etc

2 个答案:

答案 0 :(得分:1)

我认为您必须为每个收件人创建一个ContactItem,以便您可以定义名称。这是一个例子:

Sub testdistlist()

    Dim oRecips As Recipients
    Dim ciDist As DistListItem
    Dim ci As ContactItem
    Dim mi As MailItem

    Set mi = Application.CreateItem(olMailItem)
    Set oRecips = mi.Recipients

    Set ciDist = Application.CreateItem(olDistributionListItem)

    'replace this with your recordset loop
    Set ci = Application.CreateItem(olContactItem)
    ci.FirstName = "John"
    ci.LastName = "Lennon"
    ci.Email1Address = "jlennon@example.com"
    ci.Save

    oRecips.Add ci.FullName

    Set ci = Application.CreateItem(olContactItem)
    ci.FirstName = "Ringo"
    ci.LastName = "Starr"
    ci.Email1Address = "rstarr@example.com"
    ci.Save

    oRecips.Add ci.FullName
    'end replace

    ciDist.AddMembers oRecips

    ciDist.Save
    ciDist.Display
    mi.Close olDiscard

End Sub

答案 1 :(得分:1)

感谢Dick Kusleika的回答,但Graeme's answer here给了我一个想法,可以有一个更简单的方法。

这只是在分发列表的条目中使用尖括号。与"Ringo Starr<rstarr@example.com>"

中一样

哪种方法很好。

所以我原来的例子看起来像这样:

objRecipients.Add RS!FullName & "<" & RS!Email & ">"