'Track Email Category change in public shared folder only if I make the change

I have code to track changes in the Category of emails in a Public (Shared) Folder.

I have set up the code to be able to switch it "on/off", and this code is in ThisOutlookSession:

Private WithEvents myOlItems  As Outlook.Items

Private Sub myOlItems_ItemChange(ByVal Item As Object)
    Dim prompt As String
    prompt = Item.Categories
    If MsgBox(prompt, vbYesNo + vbQuestion) = vbYes Then
        'do stuff
    End If
End Sub

Sub TriggerOn()
Dim olApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Set olApp = Outlook.Application
Set objNS = olApp.GetNamespace("MAPI")
Set myOlItems = Outlook.Session.Folders("SampleMailBox").Folders("Inbox").Items
End Sub

Sub TriggerOff()
Dim olApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Set olApp = Outlook.Application
Set objNS = olApp.GetNamespace("MAPI")
Set myOlItems = Nothing
End Sub

Since this a Public Shared Folder, if any other user makes a change, the code will be triggered.

I want to track only the changes that I make.



Solution 1:[1]

You can check out the CurrentUser property of the Namespace class. The property returns the display name of the currently logged-on user as a Recipient object. So, if it is you, you can run the code (display a message box and etc.).

Solution 2:[2]

Check the value of the PR_LAST_xyz properties (PR_LAST_MODIFIER_NAME, PR_LAST_MODIFIER_ENTRYID, etc.) These properties can be accessed using MailItem.PropertyAccessor.GetProperty. Take a look at the messages with OutlookSpy (I am its author - click IMessage button) to see the available properties and their values as well as the property DASL names that you will need to use when calling GetProperty.

Another solution would be to use MailItem.Write event. If you assume that the category can be modified from the right click on the message only and a message must be selected before it is modified, you can track the Explorer.SelectionChange event, set up event sinks on the selected messages, and track the MailItem.Write event.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Eugene Astafiev
Solution 2