Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Jordon Willis   on Sep 18 In MS Office Category.

  
Question Answered By: Clinton Edwards   on Sep 18

Here is a function that will open an Outlook Distribution List, and get
each email address.

Sub SendEmail

With Outlook.CreateItem(olMailItem)
.To = GetList("Distribution List Name") 'See function below
.Subject = "Daily Inventory " & sSubject
.Attachments.Add sFile
.Send
End With

End Sub

Function GetList(sWhichList As String) As String
On Error GoTo GetListErr:

Dim objOutlook As New Outlook.Application
Dim objNameSpace As Namespace
Dim Contacts As MAPIFolder
Dim DistList As Outlook.DistListItem
Dim i As Integer

'Open contact list in personal folder, and identify distribution list
Set objNameSpace = GetNamespace("MAPI")
Set Contacts = objNameSpace.Folders("Personal
Folders").Folders("Contacts")'Identify folder hierarchy where your
distribution list is located.
Set DistList = Contacts.Items(sWhichList)
'Enter all members of list into email
For i = 1 To DistList.MemberCount
GetList = GetList & DistList.GetMember(i).Name & ";"
Next

GetListExit:
Set DistList = Nothing
Set objOutlook = Nothing
Set objNameSpace = Nothing
Set Contacts = Nothing
Exit Function

GetListErr:
Resume GetListExit:
End Function

Share: 

 

This Question has 4 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on How to send mails with multiple attachments Or get search suggestion and latest updates.


Tagged: