3
votes

I search a way to get the event of a moving item/email in outlook.

Can we use an Inspector? Or maybe there's an event handler like itemsent or newmail?

Thank you


More Details :

I have 4 or more mail boxes. Each has an number X of folders and subfolders (1 of them is a livelink box with millions of folders). Some are common box, and there are people who drag common mail.

I want to catch every time a mail is moved on a folder in livelink box.

1

1 Answers

3
votes

An event is fired when an item is added to a collection, in a folder. For example, suppose you had a folder called "Stuff" one level below your default Inbox. This code would fire every time an email was moved to that folder:

Private WithEvents Items As Outlook.Items

Private Sub Application_Startup()
  Dim olApp As Outlook.Application

  Set olApp = Outlook.Application
  Set Items = GetNS(olApp).GetDefaultFolder(olFolderInbox).Folders("Stuff").Items
End Sub

Private Sub Items_ItemAdd(ByVal item As Object)

  On Error GoTo ErrorHandler

  MsgBox "You moved an item into the 'Stuff' folder."

ProgramExit:
  Exit Sub
ErrorHandler:
  MsgBox Err.Number & " - " & Err.Description
  Resume ProgramExit
End Sub

Function GetNS(ByRef app As Outlook.Application) As Outlook.NameSpace
  Set GetNS = app.GetNamespace("MAPI")
End Function

Paste this into ThisOutlookSession and restart Outlook. Whenever an email is moved to that folder you will see the popup.