Ensuring the contacts in a Distribution List are displayed with both name and email address
-
03-10-2019 - |
문제
How can I ensure the contacts I add to an Outlook distribution list are displayed with both name and email address? These contacts may not exist in any other address book, just the distribution list. Currently they show up just as an email address (in both columns).
alt text http://img52.imageshack.us/img52/1804/tempgg.jpg
Here's roughly the VBA we're using:
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
Thanks to Dick Kusleika for his answer but Graeme's answer here gave me an idea there could be an easier way.
And that is just to use angle brackets in the entry to the distribution list. As in "Ringo Starr<rstarr@example.com>"
Which works just fine.
So my original example would look like this:
objRecipients.Add RS!FullName & "<" & RS!Email & ">"
다른 팁
I think you have to create a ContactItem for each recipient so you can define the name. Here's an example:
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