1

I wish to get the details of what has been changed in a MailItem.

I have been able to get ItemChange to trigger based upon Application.Session.Folders("TargetFolder") to a variable as such: Private Sub olInvMbxItems_ItemChange(ByVal X As Object).

I would like to know the property changed in X. If I pass X to an global variable for Private Sub X_PropertyChange(ByVal x As Object), it will miss the first iteration as X was not initialized on the first pass of ItemChange.

How can I monitor a folder of MailItems to detect Category changes. Whilst ItemChange does this, it gives duplication of action, if I look for specific categories, as many changes trigger ItemChange as mentioned here:

Handle ItemChange event when outlook appointments are dismissed

and here:

Outlook Macro that will copy an email I flag and put it in a folder

The binary flag for the UserProperties in the second item will not function as it is not a one-off event.

Outlook Events VBA says to use PropertyChange but doesn't provide a technique for implementation.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
EFH
  • 111
  • 7
  • From the further questions in what should be a reasonable if incomplete self-answer it appears you need to rethink your solution. Especially if other systems may change the item you may have to save old category codes, perhaps in a user defined field, and regularly loop the items [Run a code every half an hour](https://stackoverflow.com/questions/12257985/outlook-vba-run-a-code-every-half-an-hour), or trigger with a reminder, to see if the current cat code matches. – niton Nov 15 '17 at 17:22
  • I'm learning that direction as I get home to work the issue. If I can register a local copy to check against changes as ItemChanged is triggered, it may work well. A copy of the Categories cached as a UserProperty may work ideally. I'll update things as I progress. – EFH Nov 15 '17 at 17:26
  • You may still try for changes you do to the item but I suggest you will not recognize an ItemChange or PropertyChange done by other systems which is why in this case you would compare the current cat code to saved cat code at recurring intervals. – niton Nov 15 '17 at 17:41

2 Answers2

1

There is no way to do that - even on the MAPI level, the store provider does not keep track on what changed. Your only solution is to compare the old (saved elsewhere by you) and new values to see what changed.

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
0

Here is a method that works for a single selection. Refinement yet needed, but this is a starting point:

Private WithEvents olExplorer As Outlook.Explorer
Private olCurSel As Selection
Private WithEvents olCurSelItem As Outlook.MailItem

Private Sub olExplorer_SelectionChange()
  Set olCurSel = olExplorer.Selection
  Set olCurSelItem = Nothing
  Dim i As Long
  For i = 1 To olCurSel.Count
    If TypeName(olCurSel.Item(i)) = "MailItem" Then
      Set olCurSelItem = olCurSel.Item(i)
    End If
  Next i
End Sub

Private Sub olCurSelItem_PropertyChange(ByVal Name As String)
  Debug.Print Name; " is what changed!"
End Sub

Using Outlook.Explorer.Selection we can know that an item has been selected. We can then assign that item to and Outlook.MailItem conditionally and use the PropertyChange event of that Outlook.MailItem trigger the action we wish to take.

Problems:

  1. Does not handle multiple selections
  2. SelectionChange is triggered by the Reading Pane on each selection as well. Thus it is fired twice if the reading pane is open. As written above, olCurSelItem is set twice each SelectionChange.
  3. This is only triggered by local changes. Other systems with access to the mailbox may change the item and it will not trigger the action.
EFH
  • 111
  • 7