Event listener for deleted items

inovermyhead

Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Hello

I have the following code in ThisOutlookSession but it is not doing anything when I delete an item from my Inbox. Have I missed something?

Code:
Option Explicit 
 
Private WithEvents deletedItems As Outlook.Items 
 
Public Sub Application_Startup()
   Dim olApp As Outlook.Application
   Dim objNS As Outlook.NameSpace
   Set olApp = Outlook.Application
   Set objNS = olApp.GetNamespace("MAPI")
   Set deletedItems = objNS.GetDefaultFolder(olFolderDeletedItems).Items
      
 
End Sub 
 
Private Sub deletedItems_ItemAdd(ByVal item As Object)
   Debug.Print deletedItems.Items(i).EntryID 
 
End Sub
Thanks in advance

John
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Do you get any error messages? I'm getting an error on the debug.print line - if you aren't getting an error, then the macro is not running. Did you click in application startup to kick start the macro? Do you have macro security set to low?
 

inovermyhead

Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Yes I worked out that the macro was not running so adjusted the security settings as you advised and problem solved.

Thanks
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
use this the itemadd macro -

Private Sub deletedItems_ItemAdd(ByVal item As Object)

Debug.Print item.EntryID

End Sub
 

Similar threads

Top