Don't save a copy of sent emails

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.

  1. Write a procedure that assumes we don't want to save the message
  2. 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.

  3. Add a checkbox to the email form
  4. 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.

About JP

I'm just an average guy who writes VBA code for a living. This is my personal blog. Excel and Outlook are my thing, with a sprinkle of Access and Word here and there. Follow this space to learn more about VBA. Keep Reading »



Share This Article:

Share and bookmark this articledelicious buttonfacebook buttonlinkedin buttonstumbleupon buttontwitter button

This article is closed to any future comments.
Excel School