VBOffice

Delete the Read Email And Open the Next One

See how to open the next email and delete the one you've just read.

Last modified: 2007/01/08 | Accessed: 50.042  | #40
◀ Previous sample Next sample ▶
OLKeeper OLKeeper
OLKeeper reliably prevents users from closing their Outlook window and thus possibly missing reminders or e-mails.

If you have opened an e-mail then you can use two toolbar buttons to move to the next or previous e-mail. If you move on and want to delete the read e-mail then that's not easy: Either you switch to the folder view, select the formerly read e-mail and hit detele, or you have to delete the currently opened e-mail before moving to the next item - but then the window closes and you can't move easily to the next item.

This sample shows how to move with a single click to the next e-mail and delete the read one.

Note: The sample doesn't work in Outlook 2000 if word is your mail editor because then the NewInspector event doesn't fire.

When the e-mail window is opened, please customize the toolbar and create a new button that calls the 'NextItemAndDeleteCurrent' function.


tip  How to add macros to Outlook
Private WithEvents m_Inspectors As Outlook.Inspectors
Private WithEvents m_Inspector As Outlook.Inspector
Private WithEvents m_NextButton As Office.CommandBarButton

Private Sub Application_Startup()
  Set m_Inspectors = Application.Inspectors
End Sub

Private Sub m_Inspector_Close()
  Set m_NextButton = Nothing
  Set m_Inspector = Nothing
End Sub

Private Sub m_Inspectors_NewInspector(ByVal Inspector As Outlook.Inspector)
  Dim obj As Object

  If Len(Inspector.CurrentItem.EntryID) Then
    Set m_Inspector = Inspector
    Set obj = Inspector.CommandBars.FindControl(, 360)
    If TypeOf obj Is Office.CommandBarPopup Then
      Set m_NextButton = obj.Controls(1)
    Else
      Set m_NextButton = obj
    End If
  End If
End Sub

Public Sub NextItemAndDeleteCurrent()
  Dim CurrItem As Object

  Set CurrItem = Application.ActiveInspector.CurrentItem
  If Len(CurrItem.EntryID) Then
    m_NextButton.Execute
    CurrItem.Delete
  End If
End Sub
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