Hi all,
I'm looking for help with sending multiple emails based on data in excel in a table format. I've tested it out and it works the way I need it to, except where it says TEST in the HTML table, I want it to pull in cell values - however nothing I try works (fyi completely new to this, this is a first attempt so hoping to learn):
Sub SendMailToUsers()
Dim outapp As New Outlook.Application
Dim outmail As Outlook.MailItem
Dim wks As Worksheet
Set outapp = CreateObject("outlook.application")
Set wks = Worksheets("sheet1")
For i = 3 To wks.Range("Q" & Rows.Count).End(xlUp).Row
Set outmail = outapp.CreateItem(olMailItem)
With outmail
.To = wks.Range("Q" & i).Value
.Subject = wks.Range("S" & i).Value
.BodyFormat = olFormatHTML
.HTMLBody = "<head><style>table,th,td{border:1px solid black;border-collapse:collapse;}th,td{padding:5px;}th{text-align:left;}</style></head><body><h2>Remittance Advice</h2><table style=width:50%><tr><th>Reference</th><th>Amount</th></tr><tr><td>TEST</td><td>TEST</td></tr></tr></table>"
.CC = wks.Range("R" & i).Value
.Send
End With
On Error GoTo 0
Set outmail = Nothing
Next i
Set outapp = Nothing
End Sub
I'm looking for help with sending multiple emails based on data in excel in a table format. I've tested it out and it works the way I need it to, except where it says TEST in the HTML table, I want it to pull in cell values - however nothing I try works (fyi completely new to this, this is a first attempt so hoping to learn):
Sub SendMailToUsers()
Dim outapp As New Outlook.Application
Dim outmail As Outlook.MailItem
Dim wks As Worksheet
Set outapp = CreateObject("outlook.application")
Set wks = Worksheets("sheet1")
For i = 3 To wks.Range("Q" & Rows.Count).End(xlUp).Row
Set outmail = outapp.CreateItem(olMailItem)
With outmail
.To = wks.Range("Q" & i).Value
.Subject = wks.Range("S" & i).Value
.BodyFormat = olFormatHTML
.HTMLBody = "<head><style>table,th,td{border:1px solid black;border-collapse:collapse;}th,td{padding:5px;}th{text-align:left;}</style></head><body><h2>Remittance Advice</h2><table style=width:50%><tr><th>Reference</th><th>Amount</th></tr><tr><td>TEST</td><td>TEST</td></tr></tr></table>"
.CC = wks.Range("R" & i).Value
.Send
End With
On Error GoTo 0
Set outmail = Nothing
Next i
Set outapp = Nothing
End Sub