Hi I'm trying to set up emails to send out based on the list of names, email addresses and body text in the excel sheet. each line is for a new email recipient. I created and tested code that works perfectly for sending to just this one email but now I want code that would loop and would send more emails if i had another employee in line 3, 4, ..ect.
.
this is the code that worked for me:
Sub sending_the_email_worked()
Dim OutlookApp As Outlook.Application
Dim OutlookMail As Outlook.MailItem
Set OutlookApp = New Outlook.Application
Set OutlookMail = OutlookApp.CreateItem(olMailItem)
Dim ToName As String
Dim EmpName As String
Dim strMsg As String
ToName = Range("A2").Value
EmpName = Range("B2").Value
strMsg = Range("C2").Value
With OutlookMail
.To = ToName
.CC = ""
.BCC = ""
.Subject = EmpName & ", Your timesheets needs attention!"
.Display
.HTMLBody = "<p style='font-family:calibri;font-size:16'>Hi " & EmpName & "," & "<br><br>" & strMsg & "<br><br>" & "Thank you,</p>" & .HTMLBody
.Send
End With
End Sub
.
this is the code that worked for me:
Sub sending_the_email_worked()
Dim OutlookApp As Outlook.Application
Dim OutlookMail As Outlook.MailItem
Set OutlookApp = New Outlook.Application
Set OutlookMail = OutlookApp.CreateItem(olMailItem)
Dim ToName As String
Dim EmpName As String
Dim strMsg As String
ToName = Range("A2").Value
EmpName = Range("B2").Value
strMsg = Range("C2").Value
With OutlookMail
.To = ToName
.CC = ""
.BCC = ""
.Subject = EmpName & ", Your timesheets needs attention!"
.Display
.HTMLBody = "<p style='font-family:calibri;font-size:16'>Hi " & EmpName & "," & "<br><br>" & strMsg & "<br><br>" & "Thank you,</p>" & .HTMLBody
.Send
End With
End Sub