Creating multiple emails with different details

godzilla185

New Member
Joined
Sep 27, 2021
Messages
18
Office Version
  1. 365
Platform
  1. Windows
HI, I have seen threads on creating multiple different emails based on different data in my excel, but I am looking for a slightly diff (and hopefully easier) alternative.

I have the following code which opens up an email and prepopulates it for me without referencing any excel data or cells:

Sub allemailsin1()
'open outlook ready to send email
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
todays_date = Date$

With OutMail
.Display
End With
Signature = OutMail.body

With OutMail
.To = "person1"
.CC = "myself@gmail.com"
.BCC = ""
.Subject = "test 1 " & " " & Date$
.body = " HI," & vbNewLine & vbNewLine & "Hope you had a great day" & vbNewLine & vbNewLine & Signature
.Display

End With
End Sub

I just want to somehow loop this so that it can do what it does but x3/4 times and open NEW emails and populate them with To = "person2"... "person3" ... The reason is I have certain emails I have to repeat every single day and this would prepare the templates for me in the easiest way without having to worry about excel data or sheets.

Is anyone able to help me with this? I appreciate your time.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
How about:

VBA Code:
Sub allemailsin1()
  Dim OutApp As Object, OutMail As Object
  Dim i As Long
  
  For i = 1 To 4
    'open outlook ready to send email
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    
    With OutMail
      .Display
      .To = "person" & i
      .CC = "myself@gmail.com"
      .BCC = ""
      .Subject = "test " & i & " " & " " & Date$
      .body = " HI," & vbNewLine & vbNewLine & "Hope you had a great day" & vbNewLine & vbNewLine & .body
      .Display
    End With
  Next
End Sub
 
Upvote 0
How about:

VBA Code:
Sub allemailsin1()
  Dim OutApp As Object, OutMail As Object
  Dim i As Long
 
  For i = 1 To 4
    'open outlook ready to send email
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
   
    With OutMail
      .Display
      .To = "person" & i
      .CC = "myself@gmail.com"
      .BCC = ""
      .Subject = "test " & i & " " & " " & Date$
      .body = " HI," & vbNewLine & vbNewLine & "Hope you had a great day" & vbNewLine & vbNewLine & .body
      .Display
    End With
  Next
End Sub
Thank you.

Would I be able to change the To/CC/Subject/Body of those 4 diff emails or would they all be the exact same? Please let me know how.

I appreciate your time.
 
Upvote 0
Would I be able to change the To/CC/Subject/Body of those 4 diff emails or would they all be the exact same? Please let me know how.
What do you want to put in each case. For that they use references to cells, to take data from different cells.
 
Upvote 0
What do you want to put in each case. For that they use references to cells, to take data from different cells.
Ahh ok, yea I wanted to have fixed data that didn't depend on references to cells, if possible.

For example,

1st email is out
To: Person1...
Subject:"text1"

then

2nd email is
To: Person2
Subject; "text2"

then
3rd email is
To:Person3
Subject: "text3"

So the data would be static in the code, the emails would be diff but wouldn't reference cells.

Not sure if that is possible. I was thinking maybe some small loop that copied the 1st formula but used diff static inputs or some kind of IF-then that makes the formula repeat 4 times with diff To/CC/Subject...

Let me know if possible
 
Upvote 0
Try this:

VBA Code:
Sub allemailsin1()
  Dim OutApp As Object, OutMail As Object
  Dim i As Long
  
  For i = 1 To 4
    'open outlook ready to send email
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    
    With OutMail
      .Display
      .To = "person" & i
      .CC = "cc" & i
      .BCC = "bcc" & i
      .Subject = "text" & i
      .body = "body" & i & vbNewLine & vbNewLine & .body
      .Display
    End With
  Next
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,223,275
Messages
6,171,127
Members
452,381
Latest member
Nova88

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