VBA Send one auto email to Multiple Recipients

nrah

New Member
Joined
Jun 17, 2021
Messages
3
Hi, I want to send one email to multiple recipients, the code I have gives multiple emails with the same body and subject. How do I do it as here is my code


'Late Binding
Sub Send_Multiple_Email()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Sheet1")

Dim OA As Object
Dim msg As Object

'Create the Outlook application
Set OA = CreateObject("Outlook.Application")
Dim i As Integer
Dim last_row As Integer
'Dim mail_ids As String

last_row = Application.WorksheetFunction.CountA(sh.Range("A:A"))
Set msg = OA.createitem(0)



For i = 2 To last_row
Set msg = OA.createitem(0)


msg.To = sh.Range("A" & i).Value
msg.cc = sh.Range("B" & i).Value
msg.Subject = sh.Range("E" & i).Value
msg.body = sh.Range("G" & i).Value

'If sh.Range("E" & i).Value <> "" Then
'msg.attachments.Add sh.Range("E" & i).Value
'End If

msg.display

Next i

MsgBox "Mail Sent"


End Sub
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Not sure what to do about the cc, subject and body. But to send to the emails in A:

VBA Code:
'Late Binding
Sub Send_Multiple_Email()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Sheet1")

Dim OA As Object
Dim msg As Object

'Create the Outlook application
Set OA = CreateObject("Outlook.Application")
Dim i As Integer
Dim last_row As Integer
'Dim mail_ids As String

last_row = Application.WorksheetFunction.CountA(sh.Range("A:A"))
Set msg = OA.createitem(0)




Set msg = OA.createitem(0)

For i = 2 To last_row
msg.To = msg.To & ";" & sh.Range("A" & i).Value
Next i
msg.cc = sh.Range("B" & i).Value
msg.Subject = sh.Range("E" & i).Value
msg.body = sh.Range("G" & i).Value

'If sh.Range("E" & i).Value <> "" Then
'msg.attachments.Add sh.Range("E" & i).Value
'End If

msg.display



MsgBox "Mail Sent"


End Sub
 
Upvote 0
Solution
Not sure what to do about the cc, subject and body. But to send to the emails in A:

VBA Code:
'Late Binding
Sub Send_Multiple_Email()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Sheet1")

Dim OA As Object
Dim msg As Object

'Create the Outlook application
Set OA = CreateObject("Outlook.Application")
Dim i As Integer
Dim last_row As Integer
'Dim mail_ids As String

last_row = Application.WorksheetFunction.CountA(sh.Range("A:A"))
Set msg = OA.createitem(0)




Set msg = OA.createitem(0)

For i = 2 To last_row
msg.To = msg.To & ";" & sh.Range("A" & i).Value
Next i
msg.cc = sh.Range("B" & i).Value
msg.Subject = sh.Range("E" & i).Value
msg.body = sh.Range("G" & i).Value

'If sh.Range("E" & i).Value <> "" Then
'msg.attachments.Add sh.Range("E" & i).Value
'End If

msg.display



MsgBox "Mail Sent"


End Sub
Thank YOU!!
 
Upvote 0

Forum statistics

Threads
1,214,975
Messages
6,122,538
Members
449,088
Latest member
RandomExceller01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top