Hi all,
I have created the below macro to help with sending emails to multiple clients in a table. 'm getting error 440 - property is read-only. I'm looking to attach a pdf file that is stored in the location shown below. I have verified the path works as the same path has been used on another vba project I've completed.
I cant seem to figure out why I'm getting this message and any help would b greatly appreciated.
Here's what I've done s far;
I have created the below macro to help with sending emails to multiple clients in a table. 'm getting error 440 - property is read-only. I'm looking to attach a pdf file that is stored in the location shown below. I have verified the path works as the same path has been used on another vba project I've completed.
I cant seem to figure out why I'm getting this message and any help would b greatly appreciated.
Here's what I've done s far;
Code:
Sub Send_email()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Customer_Data")
Dim Outlook As Object
Dim msg As Object
Dim BCCTemp, SubjTemp, BdyTemp, FrmTemp As String
Set Outlook = CreateObject("outlook.application")
Dim i As Integer
Dim last_row As Integer
last_row = Application.WorksheetFunction.CountA(sh.Range("F:F")) + 2
For i = 4 To last_row
Set msg = Outlook.createitem(0)
If sh.Range("G" & i) = ""
If sh.Range("B" & i).Value = "Test1" Then
FrmTemp = "[EMAIL="Test1@hotmail.co.uk"]Test1@hotmail.co.uk[/EMAIL]"
BCCTemp = "[EMAIL="test1@hotmail.co.uk"]test1@hotmail.co.uk[/EMAIL]"
SubjTemp = "Important information"
BdyTemp = "Dear " & sh.range("A" & i).value
elseif sh.Range("B" & i).Value = "Test2" Then
FrmTemp = "[EMAIL="Test2@hotmail.co.uk"]Test2@hotmail.co.uk[/EMAIL]"
BCCTemp = "[EMAIL="test2@hotmail.co.uk"]test2@hotmail.co.uk[/EMAIL]"
SubjTemp = "Important information"
BdyTemp = "Dear " & sh.range("A" & i).value
End If
'Email template
msg.To = sh.Range("F" & i).Value
msg.SentOnBehalfOfName = FrmTemp
msg.bcc = BCCTemp
msg.Subject = SubjTemp
msg.body = BdyTemp
msg.attachments.Add = "D:\users\owen\desktop\Important Information.pdf"
msg.display
If sh.Range("G" & i).Value = "Sent" Then
Else
sh.Range("G" & i) = "Sent"
End If
End If
Next i
End Sub
Last edited: