Single email with multiple email addresses from selected cells

Kevalson

New Member
Joined
Apr 16, 2002
Messages
22
Office Version
  1. 2013
Platform
  1. Windows
Hello all.
I found a code that will allow me to create the command button that will create multiple Outlook emails, 1 for each email in a different selected cell.

What I need it to do is instead of multiple single emails, it would create just 1 single email with the multiple email addresses from the selected cells.
The email addresses in the "To" would of course have to have the "; " to separate the email addresses.

I borrowed the code from
https://www.extendoffice.com/documents/excel/4717-excel-macro-send-email-to-address-in-cells.html

I suspect it is a small tweak, but I am still learning.

Any help would be appreciated.

Code below:

Sub SendEmailToAddressInCells()
Dim xRg As Range
Dim xRgEach As Range
Dim xRgVal As String
Dim xAddress As String
Dim xOutApp As Outlook.Application
Dim xMailOut As Outlook.MailItem
On Error Resume Next
xAddress = ActiveWindow.RangeSelection.Address
Set xRg = Application.InputBox("Please select email address range", "KuTools For Excel", xAddress, , , , , 8)
If xRg Is Nothing Then Exit Sub
Application.ScreenUpdating = False
Set xOutApp = CreateObject("Outlook.Application")
Set xRg = xRg.SpecialCells(xlCellTypeConstants, xlTextValues)
For Each xRgEach In xRg
xRgVal = xRgEach.Value
If xRgVal Like "?*@?*.?*" Then
Set xMailOut = xOutApp.CreateItem(olMailItem)
With xMailOut
.To = xRgVal
.Subject = "Test"
.Body = "Dear " _
& vbNewLine & vbNewLine & _
"This is a test email " & _
"sending in Excel"
.Display
'.Send
End With
End If
Next
Set xMailOut = Nothing
Set xOutApp = Nothing
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Instead of having a loop for each address in the range include the mail, concatenate the addresses in a loop then create the mail.

Code:
Sub SendEmailToAddressInCells()
 Dim xRg As Range
 Dim xRgEach As Range
 Dim xRgVal As String
 Dim xAddress As String
 Dim xOutApp As Outlook.Application
 Dim xMailOut As Outlook.MailItem
 On Error Resume Next
 xAddress = ActiveWindow.RangeSelection.Address
 Set xRg = Application.InputBox("Please select email address range", "KuTools For Excel", xAddress, , , , , 8)
 If xRg Is Nothing Then Exit Sub
 Application.ScreenUpdating = False
 Set xOutApp = CreateObject("Outlook.Application")
 Set xRg = xRg.SpecialCells(xlCellTypeConstants, xlTextValues)
 For Each xRgEach In xRg
 xRgVal = xRgEach.Value
 If xRgVal Like "?*@?*.?*" Then
 mailTo = mailTo & xRgVal & " ;"
 MsgBox (mailTo) -----------------I just include this to test. 
 End If
 Next
 Set xMailOut = xOutApp.CreateItem(olMailItem)
 With xMailOut
 .To = mailTo
 .Subject = "Test"
 .Body = "Dear " _
 & vbNewLine & vbNewLine & _
 "This is a test email " & _
 "sending in Excel"
 .Display
 '.Send
 End With
 
 Set xMailOut = Nothing
 Set xOutApp = Nothing
 Application.ScreenUpdating = True
 End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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