In Prompt to save a copy or not when sending emails, a reader asks if he can avoid saving a copy of a sent message.
The easy way is to use a VBA event handler. After clicking Send, you'll be prompted to save the message. If not, the sent message is saved in the local Deleted Items folder (instead of the Sent Items folder).
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim msg As Outlook.MailItem
If TypeName(Item) = "MailItem" Then ' it's an email
Set msg = Item
If MsgBox("Save this item?", vbYesNo) = vbNo Then ' delete it
Set msg.SaveSentMessageFolder = _
Session.GetDefaultFolder(olFolderDeletedItems)
End If
End If
End Sub
A more roundabout way would be like this:
Private WithEvents objExplorer As Outlook.Explorer
Private WithEvents msg As Outlook.mailItem
Private WithEvents replyMsg As Outlook.mailItem
Private Sub Application_Startup()
Set objExplorer = Application.ActiveExplorer
End Sub
Private Sub objExplorer_SelectionChange()
' use SelectionChange event to grab the currently selected item
If objExplorer.CurrentFolder.DefaultItemType = olMailItem Then
If objExplorer.Selection.count > 0 Then
If TypeName(objExplorer.Selection(1)) = "MailItem" Then
Set msg = objExplorer.Selection(1)
End If
End If
End If
End Sub
Private Sub msg_Reply(ByVal Response As Object, Cancel As Boolean)
' grab the reply
Set replyMsg = Response
End Sub
Private Sub msg_ReplyAll(ByVal Response As Object, Cancel As Boolean)
' grab the reply all
Set replyMsg = Response
End Sub
Private Sub replyMsg_Send(Cancel As Boolean)
' when sending, ask if save is needed
If MsgBox("Save this item?", vbYesNo) = vbNo Then ' delete it
Set replyMsg.SaveSentMessageFolder = _
Session.GetDefaultFolder(olFolderDeletedItems)
End If
End Sub
See Where do I put my Outlook VBA code? for placement assistance.
Problem is, every time you send an email, you're going to see the prompt. That can get annoying after a while. There are a couple of ways to mitigate this.
- Write a procedure that assumes we don't want to save the message
- Add a checkbox to the email form
Instead of reacting a message already being sent, let's create a message that already is set to not be saved.
Sub DontSaveMsg()
Dim msg As Outlook.MailItem
Set msg = Outlook.CreateItem(olMailItem)
With msg
Set .SaveSentMessageFolder = _
Session.GetDefaultFolder(olFolderDeletedItems)
.Display
End With
End Sub
This code may be attached to a toolbar button or added to the QAT. Whenever you want to send an email that you don't want to save, just click the button.
In my opinion this is the best option. We can modify an existing form to add a checkbox. You don't have to respond to a dialog box with every sent email, you just check the box when you don't want to save the email, or set it up to be checked by default. We will go over this in a future blog post. For now, the VBA code is an excellent stopgap.
Follow Me