VBA Macro to send multiple unique emails to unique addresses

monkeymaster

New Member
Joined
Oct 15, 2021
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi,

I am trying to create a VBA macro that will generate outlook emails based on unique information in the cells. Every email is different and is going to different people. I need it to be able to generate numerous emails at a time without having to rerun the script. My file is set up so that column A is the 'To:" column B is 'CC', column C is the subject, and column D is the email.

Does anyone have a VBA code that will loop through these cells and generate previews of the emails?

To​
CC​
Subject​
Email​
test​
another test​
test2​
another test 2​
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Welcome to the forum.

Check out this thread:


It should be easy enough to adapt that to get the subject and body from the spreadsheet. Change .Send to .Display to preview them before sending.
 
Upvote 0
So I have the code as below but can't figure out how to get the cc, subject, and body to update for each unique email within the rows.

Sub Mail_Workbooks()
Dim OutApp As Object, OutMail As Object, WS As Worksheet, r As Long


Set OutApp = CreateObject("Outlook.Application")

Set WS = Sheets("MACRO")
On Error Resume Next


For r = 2 To WS.Cells(Rows.Count, "A").End(xlUp).Row

With OutApp.CreateItem(0)
.To = WS.Cells(r, 1).Value
.CC = Range("B2")
.Subject = Range("c2")
.Body = Range("d2"
)
.Display
End With
DoEvents
Next r

On Error GoTo 0
Set OutApp = Nothing
End Sub
 
Upvote 0
This is untested, but should give you the idea:

VBA Code:
Sub Mail_Workbooks()
Dim OutApp As Object, OutMail As Object, WS As Worksheet, r As Long


    Set OutApp = CreateObject("Outlook.Application")

    Set WS = Sheets("MACRO")
    On Error Resume Next

    For r = 2 To WS.Cells(Rows.Count, "A").End(xlUp).Row

        With OutApp.CreateItem(0)
            .To = WS.Cells(r, "A").Value
            .CC = WS.Cells(r, "B").Value
            .Subject = WS.Cells(r, "C").Value
            .Body = WS.Cells(r, "D").Value
            .Display
        End With
        DoEvents
    Next r

    On Error GoTo 0
    Set OutApp = Nothing
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,695
Messages
6,126,263
Members
449,307
Latest member
Andile

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