Larsona
04-10-2017, 05:04 AM
Hello,
I am receiving plenty of emails from POP accounts used on different devices. Unfortunate the users set different names in the different configs and so it is difficult to search and sort. As the sender are mostly located in Far East there are also variants in local characters which is not helpful. Therefor I tried my best to write a small VB code which set a unified sender name while receiving an email - one name by email address.<br>Here is what I have tried so far:<br>
Unfortunately SenderName is protected and cannot be changed and I do not find a way around. Can anyone help, please?
Sub test(MyMail As MailItem)
Dim strID As String
Dim olNS As Outlook.NameSpace
Dim olMail As Outlook.MailItem
strID = MyMail.EntryID
Set olNS = Application.GetNamespace("MAPI")
Set olMail = olNS.GetItemFromID(strID)
If olMail.SenderEmailAddress = "email.address" Then
olMail.SenderName = "John Doe"
olMail.Save
End If
Set olMail = Nothing
Set olNS = Nothing
End Sub
I am receiving plenty of emails from POP accounts used on different devices. Unfortunate the users set different names in the different configs and so it is difficult to search and sort. As the sender are mostly located in Far East there are also variants in local characters which is not helpful. Therefor I tried my best to write a small VB code which set a unified sender name while receiving an email - one name by email address.<br>Here is what I have tried so far:<br>
Unfortunately SenderName is protected and cannot be changed and I do not find a way around. Can anyone help, please?
Sub test(MyMail As MailItem)
Dim strID As String
Dim olNS As Outlook.NameSpace
Dim olMail As Outlook.MailItem
strID = MyMail.EntryID
Set olNS = Application.GetNamespace("MAPI")
Set olMail = olNS.GetItemFromID(strID)
If olMail.SenderEmailAddress = "email.address" Then
olMail.SenderName = "John Doe"
olMail.Save
End If
Set olMail = Nothing
Set olNS = Nothing
End Sub