'Outlook event: On change 'From Address'
Solution 1:[1]
The PropertyChange event of the MailItem class is fired when an explicit built-in property (for example, Subject) of an instance is changed. Be aware, you may not get the event fired as soon as you change the value in the UI. Outlook may not fire events until the focus is moved to another field or the item is saved.
Solution 2:[2]
For completeness - here is the full code I have implemented to capture the event I am interested in.
Dim WithEvents myInspector As Outlook.Inspectors
Dim WithEvents myMailItem As Outlook.MailItem
Private Sub Application_Startup()
Set myInspector = Application.Inspectors
End Sub
Private Sub myInspector_NewInspector(ByVal Inspector As Outlook.Inspector)
If TypeOf Inspector.CurrentItem Is MailItem Then
Set myMailItem = Inspector.CurrentItem
End If
End Sub
Private Sub myMailItem_PropertyChange(ByVal Name As String)
' Properties we are interested in: "SendUsingAccount" / "SentOnBehalfOfName"
' Both get fired when the 'From' field is changed/re-selected
' So we are only going to trigger on one event or we will call the code twice
If Name = "SentOnBehalfOfName" Then
MsgBox myMailItem.SentOnBehalfOfName
End If
End Sub
Solution 3:[3]
When the message sender is changed, the following sequence of the MailItem.PropertyChange
event will fire:
PropertyChange ("SendUsingAccount")
PropertyChange ("SentOnBehalfOfName")
You can see the live events in OutlookSpy (I am its author) - open the new item, click Item button on the OutlookSpy ribbon, go to the Events tab - OutlookSpy will log the events as they are raised.
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 | |
Solution 3 | Dmitry Streblechenko |