Hello:
The code below works and will send my document to all contacts in the contacts folder.
What I'm really trying to do is send the document to only those people in my distribution list.
The distribution list is called marketing.
Public Sub SendDocToEmailList()
Dim olapp
Dim mynamespace
Dim mycontactlist
Dim mycontactsentries
Dim messagesubject
Dim newmessage
Dim i As Integer
Set olapp = CreateObject("Outlook.Application")
Set mynamespace = olapp.getnamespace("Mapi")
Set mycontactlist = mynamespace.addresslists("Contacts")
Set mycontactsentries = mycontactlist.addressentries
messagesubject = InputBox("Message subject (Blank to cancel)?")
If messagesubject = "" Then Exit Sub
For i = 1 To mycontactsentries.Count
Set newmessage = olapp.createitem(olmailitem)
newmessage.Subject = messagesubject
newmessage.body = ActiveDocument.Content.Text
newmessage.to = mycontactsentries(1).Address
newmessage.send
Set newmessage = Nothing
Next i
MsgBox "Your messages have been sent."
Set olapp = Nothing
Set mynamespace = Nothing
Set mycontactslist = Nothing
Set mycontactsentries = Nothing
End Sub
Thank you
Gary W. Hill
The code below works and will send my document to all contacts in the contacts folder.
What I'm really trying to do is send the document to only those people in my distribution list.
The distribution list is called marketing.
Public Sub SendDocToEmailList()
Dim olapp
Dim mynamespace
Dim mycontactlist
Dim mycontactsentries
Dim messagesubject
Dim newmessage
Dim i As Integer
Set olapp = CreateObject("Outlook.Application")
Set mynamespace = olapp.getnamespace("Mapi")
Set mycontactlist = mynamespace.addresslists("Contacts")
Set mycontactsentries = mycontactlist.addressentries
messagesubject = InputBox("Message subject (Blank to cancel)?")
If messagesubject = "" Then Exit Sub
For i = 1 To mycontactsentries.Count
Set newmessage = olapp.createitem(olmailitem)
newmessage.Subject = messagesubject
newmessage.body = ActiveDocument.Content.Text
newmessage.to = mycontactsentries(1).Address
newmessage.send
Set newmessage = Nothing
Next i
MsgBox "Your messages have been sent."
Set olapp = Nothing
Set mynamespace = Nothing
Set mycontactslist = Nothing
Set mycontactsentries = Nothing
End Sub
Thank you
Gary W. Hill