Thanks in advance for your help!
I am trying to send a spreadsheet range in the body of an email to multiple recipients. Below is my code which is set to display the email for testing (I will change to msg.send later).
The code stops at
"msg.body = sh.Range("D5:O" & last_row).Value"
with an error message of "The object does not support this method."
Any thoughts on what I have done wrong?
Sub Send_Mail()
'
' Send_Mail Macro
'
Dim OA As Object
Set OA = CreateObject("outlook.application")
Dim sh As Worksheet
Dim last_row As Integer
Name = Cells(7, 51)
last_row = Cells(15, 20) + 6
Set sh = ThisWorkbook.Sheets(Name)
Dim i As Integer
Dim r As Long
For i = 7 To last_row
With Selection.Parent.MailEnvelope.Item
Set msg = OA.createitem(0)
msg.To = sh.Range("AX" & i).Value
msg.Subject = sh.Range("Az7").Value
msg.body = sh.Range("D5:O" & last_row).Value
msg.display
End With
Next i
sh.Range("aw" & i).Value = "Sent"
MsgBox "All the mails have been sent successfully"
End Sub
Thanks again for your assistance.
I am trying to send a spreadsheet range in the body of an email to multiple recipients. Below is my code which is set to display the email for testing (I will change to msg.send later).
The code stops at
"msg.body = sh.Range("D5:O" & last_row).Value"
with an error message of "The object does not support this method."
Any thoughts on what I have done wrong?
Sub Send_Mail()
'
' Send_Mail Macro
'
Dim OA As Object
Set OA = CreateObject("outlook.application")
Dim sh As Worksheet
Dim last_row As Integer
Name = Cells(7, 51)
last_row = Cells(15, 20) + 6
Set sh = ThisWorkbook.Sheets(Name)
Dim i As Integer
Dim r As Long
For i = 7 To last_row
With Selection.Parent.MailEnvelope.Item
Set msg = OA.createitem(0)
msg.To = sh.Range("AX" & i).Value
msg.Subject = sh.Range("Az7").Value
msg.body = sh.Range("D5:O" & last_row).Value
msg.display
End With
Next i
sh.Range("aw" & i).Value = "Sent"
MsgBox "All the mails have been sent successfully"
End Sub
Thanks again for your assistance.