3

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.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
forX
  • 2,063
  • 2
  • 26
  • 47

1 Answers1

3

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.

JimmyPena
  • 8,694
  • 6
  • 43
  • 64
  • yeah, well, you use items, but I have 4 mail box (some are commun box), and I have a box with millions folders(livelink box if you know is it). the problem seems to be the items list, or maybe I can set the list when a folder is selected, I think I wasn't enough accurate on my first question – forX Nov 04 '11 at 15:31
  • There's no real "Item Move" event (I'd love to hear otherwise), you have to back into it by checking the ItemAdd Event. If it fires, an item was added to the items collection of the referenced folder. We simply assume (since it's not the Inbox) that the item was moved. – JimmyPena Nov 04 '11 at 15:45