Outlook VBA Delete Message After Send -


i writing macro allow me forward current message (by running macro via button on ribbon) attachment , deleting original message.

however when run macro message not deleted , receive email "system administrator" message un-deliverable.

if comment out line .deleteaftersubmit = true message sent not deleted.

dim objattachment attachment dim strattachment string set objitem = getcurrentitem() set objmsg = application.createitem(olmailitem) strattachment = ""  each objattachment in objitem.attachments     strattachment = strattachment & " " & objattachment.displayname ' filename next  objmsg     .attachments.add objitem, olembeddeditem     .subject = objitem.subject & " " & objitem.to     .to = "email@outlook.com"     .body = "from: " & objitem.sender & vbnewline & _             "sent: " & objitem.receivedtime & vbnewline & _             "to: " & objitem.to & vbnewline & _             "cc: " & objitem.cc & vbnewline & _             "subject: " & objitem.subject & vbnewline & _             "attachment: " & strattachment & vbnewline & vbnewline & _             objitem.body     .deleteaftersubmit = true     .send end 

should objitem.delete outside with...end with

with objmsg     .attachments.add objitem, olembeddeditem     .subject = objitem.subject & " " & objitem.to     .to = "email@outlook.com"     .body = "from: " & objitem.sender & vbnewline & _             "sent: " & objitem.receivedtime & vbnewline & _             "to: " & objitem.to & vbnewline & _             "cc: " & objitem.cc & vbnewline & _             "subject: " & objitem.subject & vbnewline & _             "attachment: " & strattachment & vbnewline & vbnewline & _      objitem.body     .send end  objitem.delete 

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -