CDO objmessage - How to remove attachment before a SEND
Posted on 2007-03-23
In VBA I'm sending multiple emails using the CDO object and it works very well.
I just started adding attachments and that works well, TOO well.
The source of email addresses and attachment file names are in rows in an Excel sheet.
The logic sends the first email and then loops back and only refreshes the TO and ATTACHMENT, does an UPDATE, then a SEND.
The problem is, once a message is sent with an attachement then the next email may not need an attachment, but the attachment defined will be the same until it is replaced. Replacing works fine, but when there is NO attachment I can't figure out how to remove the attachment which got staged in the previouse message. See the code for where I need to be able to so the equivilent of:
I've tried every combination I can think of and I can't seem to find a reference for the complete object model with the names of the Methods and Properties
'Send more than one email
For Row = 2 To 2000
If IsEmpty(.Cells(Row, 1)) Then Exit For
objMessage.To = .Cells(Row, 4)
If Trim(.Cells(Row, 5)) <> "" Then
em_attachment = Range("PDF_temp_files") & .Cells(Row, 5)
objMessage.AddAttachment ("file://" & em_attachment)
' I want to delete the existing staged attachment HERE
objMessage.Attachment = Nothing <--this does not work. code failure