Results 1 to 4 of 4

Thread: .attachment.add - 440 - Property is read-only

  1. #1
    New Member
    Join Date
    Dec 2014
    Posts
    38
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default .attachment.add - 440 - Property is read-only

    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;

    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 = "Test1@hotmail.co.uk"
                    BCCTemp = "test1@hotmail.co.uk"
                    SubjTemp = "Important information"
                    BdyTemp = "Dear " & sh.range("A" & i).value
                    elseif sh.Range("B" & i).Value = "Test2" Then
                    FrmTemp = "Test2@hotmail.co.uk"
                    BCCTemp = "test2@hotmail.co.uk"
                    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 by owen4512; Oct 14th, 2019 at 12:14 PM.

  2. #2
    MrExcel MVP
    Moderator
    RoryA's Avatar
    Join Date
    May 2008
    Location
    UK
    Posts
    33,993
    Post Thanks / Like
    Mentioned
    53 Post(s)
    Tagged
    6 Thread(s)

    Default Re: .attachment.add - 440 - Property is read-only

    Remove the = sign. It's just:

    Code:
     msg.attachments.add filepath

  3. #3
    New Member
    Join Date
    Dec 2014
    Posts
    38
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: .attachment.add - 440 - Property is read-only

    Quote Originally Posted by RoryA View Post
    Remove the = sign. It's just:

    Code:
     msg.attachments.add filepath
    I've been staring that this for a good few minutes thinking i was going crazy. Thanks for the help i appreciate it.

  4. #4
    MrExcel MVP
    Moderator
    RoryA's Avatar
    Join Date
    May 2008
    Location
    UK
    Posts
    33,993
    Post Thanks / Like
    Mentioned
    53 Post(s)
    Tagged
    6 Thread(s)

    Default Re: .attachment.add - 440 - Property is read-only

    Glad to help.

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •