Code to automatically delete message after sending

Status
Not open for further replies.

Alan McGowan

Senior Member
Outlook version
Outlook 2013 64 bit
Email Account
Exchange Server
I have developed code that does various things including saving incoming and outgoing emails in MSG format in a standard file naming convention in a folder the user chooses either from browsing to the folder or selecting it from a drop down list on a userform. I have set up a userform that automatically opens when you press the send button (uses Application_ItemSend to do this). On the userform that opens I have several buttons that do different things. One of them saves the email in MSG format in a chosen folder, one simply sends the email with a copy of the email being put in the Sent Items folder and the third button sends the email and deletes it. It is this third button that is giving me trouble as I can't get it to work. Any suggestions on the code I should be using bearing in mind the code will be run from a button on a userform and the userform has been opened using Application_ItemSend.

Thanks for your help
 

Alan McGowan

Senior Member
Outlook version
Outlook 2013 64 bit
Email Account
Exchange Server
I tried but couldn't get it to work probably because I got the code wrong. I tried

sub commandbutton17_click ()
dim msg as outlook.mailitem
msg.deleteaftersubmit = true
msg = nothing
End sub
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
You need to set the msg variable to the item that is going to be send.
 

Alan McGowan

Senior Member
Outlook version
Outlook 2013 64 bit
Email Account
Exchange Server
Sorry but I have very little coding experience. Can you provide some further guidance on how to do this
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
You already have two buttons doing something successfully with the message. Simply copy the code from there that references the message.
 

Alan McGowan

Senior Member
Outlook version
Outlook 2013 64 bit
Email Account
Exchange Server
Doh! copied the code as suggested and it works fine now
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
C Need VBA code to automatically save message outside outlook and add date Outlook VBA and Custom Forms 1
B how to add country code to contacts automatically Using Outlook 7
S Outllok 2007 VBA code to send mail automatically from drafts folder Using Outlook 1
M Calendar draft notice - automatically color code? Using Outlook 1
I Outlook 2003 shows html code when To: field is empty Using Outlook 5
F VBA code to dock Styles whenever I write or edit an email Outlook VBA and Custom Forms 0
S Skype for business meeting vba code Outlook VBA and Custom Forms 1
R Expand VBA Permanent Delete Code Outlook VBA and Custom Forms 6
B Outlook Business Contact Manager with SQL to Excel, User Defined Fields in BCM don't sync in SQL. Can I use VBA code to copy 1 field to another? BCM (Business Contact Manager) 0
A VBA Code in Outlook disappears after first use Outlook VBA and Custom Forms 1
Alex Cotton "invalid or unqualified reference" on code that should work Outlook VBA and Custom Forms 5
F VBA to ensure a code is entered in Subject title Outlook VBA and Custom Forms 1
Z Outlook Custom Form: Adding Dropdown(Project Code) at the end of subject Outlook VBA and Custom Forms 0
D Any updates or fixes that would make this code stop working just moving emails to another folder Outlook VBA and Custom Forms 1
N Open & Save VBAProject.Otm using VBA Code Outlook VBA and Custom Forms 1
M error code 0x8DE00006 Using Outlook 1
R VBA Code to permanently delete selected email Outlook VBA and Custom Forms 10
dyny723 Outlook 2016: Code to link a contact to emails received from that contact Outlook VBA and Custom Forms 1
D Command Button code will not execute. Any suggestions Please. Outlook VBA and Custom Forms 2
V VB script code to save a specific email attachment from a given email Outlook VBA and Custom Forms 14
J Custom form code doesn't run Outlook VBA and Custom Forms 2
M code to move selected Outlook contacts to another folder Using Outlook 3
E Outlook Form - Voting Responses Not Auto Processing If Form Contains Any Code Outlook VBA and Custom Forms 0
S Problem running Command button code Outlook VBA and Custom Forms 2
D Help with code to move mail on receipt to another folder based on time received Outlook VBA and Custom Forms 2
C Color Code New Calendar Items Using Outlook 2
S VBA Code to move mail items from search folder to inbox subfolder Outlook VBA and Custom Forms 4
B Automation error running VB macro code Outlook VBA and Custom Forms 8
S my vbscript button1_click code works on appointment created but not on opening an existing apntmn Outlook VBA and Custom Forms 16
M regarding the Create Contacts From Messages code Using Outlook 8
J Outlook 2010 VBScript editor does not run code at all Outlook VBA and Custom Forms 0
B VBA Code to create appointment from email Outlook VBA and Custom Forms 1
D VBA Code to strip Subject Line when replying or forwarding Using Outlook 3
L Outlook 2007 Contact Form Code Not Working Using Outlook 20
S The attempted operation failed ... 2nd time running code Outlook VBA and Custom Forms 3
A Check for attachment code not working Outlook VBA and Custom Forms 1
T What code to use to move the custom field values to message body when sending e-mail ? Outlook VBA and Custom Forms 8
G Annoying page of code when receiving Using Outlook 14
M VBA Code to Restart Outlook on error Outlook VBA and Custom Forms 3
Z Default VBA code for extracting data from email (Outlook) to Excel? Outlook VBA and Custom Forms 1
T VBA to Sort Rules [A-Z] - code provided Outlook VBA and Custom Forms 9
M VBA Auto-Reply code for Two Mailboxes on one Outlook Session. Outlook VBA and Custom Forms 4
Z Protecting VBA code - anything new? Outlook VBA and Custom Forms 2
S Outlook 2010 I am getting error code 0x8DE00006 'the operation failed'. outlook 2010 send/receive progress Using Outlook.com accounts in Outlook 2
G VBA code to enable a rule based on time of day for a IMAP mail account Outlook VBA and Custom Forms 14
S VBA code to rename a task (flagged message) Outlook VBA and Custom Forms 1
M VBA code to save email attachments (PDF) as email subject line Outlook VBA and Custom Forms 1
F VBA Code to change subject Like Outlook VBA and Custom Forms 3
L Delete code and commandbutton at the same time. Using Outlook 1
H Where to post code in Outlook Outlook VBA and Custom Forms 1

Similar threads

Top