VBA Code Sending Email to Multiple Recipients with Cell References instead of addresses

Michael Fowler

New Member
Joined
Jan 23, 2024
Messages
28
Office Version
  1. 2021
  2. 2016
Platform
  1. Windows
Hi everyone, I need help with this. The relevant part of my VBA Code is as follows, and it's working perfectly when sending to one recipient, with the email successfully going to the email address in cell A3 ...

With OutlookMail
.To = Range("A3").Value
.cc = ""
.BCC = ""
.Subject = "Certification Compliance"


Additionally, I found this code on the web for sending to multiple recipients ...

With OutMail
.To = EmailTo
.CC = "person1@email.com;person2@email.com"
.BCC = ""
.Subject = "RMA #" & Worksheets("RMA").Range("E1")


So, I thought that one of the following two codes would logically follow, but neither is working ...

With OutlookMail
.To = Range("A3;A4;A5").Value
.cc = ""
.BCC = ""
.Subject = "Certification Compliance"


or ...

With OutlookMail
.To = Range("A3").Value;Range("A4").Value;Range("A5").Value
.cc = ""
.BCC = ""
.Subject = "Certification Compliance"
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
The syntax you are trying to use is invalid. Normally I would use code that adds recipients, but you can do it the following way in one shot. You have to build up the string as though you were typing it into the "To" box.

VBA Code:
.To = Range("A3").Value & ";" & Range("A4").Value & ";" & Range("A5").Value
 
Upvote 1
Solution
Thank you very much, your code above worked. I'm also interested in your suggestion ... I would use code that adds recipients ... Please elaborate on what you mean. Thanks.
 
Upvote 0
There is really nothing wrong with doing it your way but you have to have all the recipients available at the time this line of code executes. If you are doing a loop or something where you can only get them one at a time, you can use this to add each new recipient:
VBA Code:
Public Sub AddRecipientTo(CurMsg As MailItem, NameAddress As String)

   Dim NewRecipient As Recipient
   
   Set NewRecipient = CurMsg.Recipients.Add(NameAddress)
   
   NewRecipient.Type = olTo
   NewRecipient.Resolve

End Sub
 
Upvote 0
Thanks Jeff, if I have any more questions on that, I'll let you know. Thanks again for your solution above, it's much appreciated. Michael
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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