2010-05-05 55 views
2

如何確保我添加到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 

回答

1

感謝迪克Kusleika他的回答卻Graeme's answer here給了我一個想法有可能是一個更簡單的方法。

而這只是在分配列表的條目中使用尖括號。如在"Ringo Starr<[email protected]>"

這工作得很好。

所以我原來的例子是這樣的:

objRecipients.Add RS!FullName & "<" & RS!Email & ">" 
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 = "[email protected]" 
    ci.Save 

    oRecips.Add ci.FullName 

    Set ci = Application.CreateItem(olContactItem) 
    ci.FirstName = "Ringo" 
    ci.LastName = "Starr" 
    ci.Email1Address = "[email protected]" 
    ci.Save 

    oRecips.Add ci.FullName 
    'end replace 

    ciDist.AddMembers oRecips 

    ciDist.Save 
    ciDist.Display 
    mi.Close olDiscard 

End Sub 
相關問題