Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sendmail once to multiple recipients.

Status
Not open for further replies.

Musikaman

Programmer
Oct 27, 2002
3
US
Hey all! I haven't used this function before and can't find syntax or arguments for it. Can someone modify this code to send 1 mail message to all the recipients rather than an individual message to each? Thanks!

Sub send_email()
' To use this code,
' Type Subject in A1
' Type body of messages in A2
' list of recipients in J3, j4 and so on
'

Dim emailx()
Dim ds, ii, i, addx, ToRecipientsList, myOlApp, olMailItem, myItem, myRecipient
ds = Worksheets("Options").Range("J1").Value
'number of recipients. I type a formula that count number of recipient in J1.
ReDim emailx(ds) 'redim array of recipients
Range("J3").Activate

' arraying recipients
For ii = 0 To ds - 1
emailx(ii) = Range("J3").Offset(ii, 0).Value
Next ii

'Get mail subject & message from worksheets

mailsubject = Range("A1").Value
Body1 = Range("A2").Value 'you can modify the message as you like

For i = 0 To ds - 1 Step 1
Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.CreateItem(olMailItem)
Set myRecipient = myItem.Recipients.Add(emailx(i))
myItem.Importance = olImportanceHigh
myItem.Subject = mailsubject
myItem.Body = Body1
myItem.send
Next i
End Sub
 
Just a matter of rearranging your original code. I also eliminated the unnecessary step of creating an array:

Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.CreateItem(olMailItem)

For i = 0 To ds - 1
myItem.Recipients.Add Range("J3").Offset(ii, 0)
next i
myItem.Importance = olImportanceHigh
myItem.Subject = mailsubject
myItem.Body = Body1
myItem.send

Rob
[flowerface]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top