Outbox does not send

Do you know the problem that an email doesn't leave the outbox? This macro addresses one of the reasons.

Last modified: 2015/09/21 | Accessed: 4.840  | #155
◀ Previous sample Next sample ▶
Reporter Reporter
VBOffice Reporter is an easy to use tool for data analysis and reporting in Outlook. A single click, for instance, allows you to see the number of hours planned for meetings the next month.

If there's a message in the outbox ready to be sent, it is displayed italic. This message must not be accessed anymore else the send process will be cancelled. When that happens, you need to open the message and again click on Send.

Many Addins or macros do access at least the first message in a folder as soon as you switch to the folder. So, if you click in an email on Send and then switch to the outbox, it will often happen that the email won't be sent. This requires self-discipline: Do not look into the outbox as long as it contains a message (except you want to edit it before sending).

This macro helps you with that:

  • If the outbox holds an email, you can only switch to it after confirming a message box.
  • If the outbox is currently viewed and you click in an email on Send, the view automatically switches to the inbox.

tip  How to add macros to Outlook
Private WithEvents m_Explorer As Outlook.Explorer

Private Sub Application_Startup() 
  Set m_Explorer = Application.ActiveExplorer
End Sub

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean) 
  If FolderIsOutbox(Application.ActiveExplorer.CurrentFolder) Then
    Set Application.ActiveExplorer.CurrentFolder = Session.GetDefaultFolder(olFolderInbox)
  End If
End Sub

Private Sub m_Explorer_BeforeFolderSwitch(ByVal NewFolder As Object, Cancel As Boolean)  
  If FolderIsOutbox(NewFolder) Then
    If NewFolder.Items.Count Then
      If MsgBox("There's a message in the outbox. If you switch to the folder, the send process will be cancelled." _
        & vbCrLf & vbCrLf & "View folder anyway?", vbYesNo Or vbQuestion Or vbDefaultButton2) <> vbYes Then
        Cancel = True
      End If
    End If
  End If
End Sub

Private Function FolderIsOutbox(F As Outlook.MAPIFolder) As Boolean
  On Error Resume Next
  Dim Outbox As Outlook.MAPIFolder
  Dim e1$, e2$
  If F Is Nothing Then Exit Function
  e1 = LCase$(F.EntryID)
  Set Outbox = Session.GetDefaultFolder(olFolderOutbox)
  e2 = LCase$(Outbox.EntryID)
  If Len(e1) > 0 And Len(e2) > 0 Then
    FolderIsOutbox = (e1 = e2)
  End If
End Function
ReplyAll ReplyAll
ReplyAll alerts you before unintentionally replying all, or if you are a confidential BCC recipient of the e-mail.
email  Send a message