Update new custom field

Status
Not open for further replies.

VTGroup

New Member
Outlook version
Outlook 2016 64 bit
Email Account
Exchange Server
I've added a custom column called "Ext" to my Inbox view in "View / View Settings / Columns...". Using VBA, I'd like to set that value to "***" for every email received from an external sender.

With some other code I got from this site, the subroutine below fires at the right time, and I see the message box when the email comes from outside my org, and I don't see it if it's from inside my org.

But nothing I've tried will fill in the new column in my Inbox view. I assume I'm missing the relationship between adding a custom column and creating a user-defined property. Any help would be much appreciated.

Private Sub objNewMailItems_ItemAdd(ByVal Item As Object)
If Item.Class <> olMail Then Exit Sub
If (InStr(Item.SenderEmailAddress, "@")) Then
MsgBox ("Out: " & Item.SenderEmailAddress)
End If
End Sub
 
That code is just checking the address - There is a code sample on this page that shows how to write fields


(Yeah, I know the page is looking goofy - fixing that next).
 
I'll try that now. Thank you for the reply.

And I'll use this thread to let you know that in the last couple of years, almost all of my hard VBA problems have been solved by one of your posts, so I want to thank you for that as well!
 
It worked. I'm not sure what I missed before, as I tried numerous variations of UserProperties calls. (I should have actually included my various attempts in my original post, instead of just showing the placeholder MsgBox.)

Using your post as a guide, I ended up with the following. After adding a custom field called "Ext" to my Inbox, every "sent from an external sender" email now shows "***" in the "Ext" column.

Code:
Private objNS As Outlook.NameSpace
Private WithEvents objNewMailItems As Outlook.Items

Private Sub Application_Startup()
    Dim objMyInbox As Outlook.MAPIFolder

    Set objNS = Application.GetNamespace("MAPI")
    Set objMyInbox = objNS.GetDefaultFolder(olFolderInbox)
    Set objNewMailItems = objMyInbox.Items
    Set objMyInbox = Nothing
End Sub

Private Sub objNewMailItems_ItemAdd(ByVal Item As Object)
    If Item.Class <> olMail Then Exit Sub
    If (InStr(Item.SenderEmailAddress, "@")) Then
        Dim objProp As Outlook.UserProperty
        Set objProp = Item.UserProperties.Add("Ext", olText, True)
        objProp.Value = "***"
        Item.Save
    End If
End Sub
 
Last one. I found that this is a better look than "***". Just make the custom field "Yes/No" and "Icon".

Code:
Private Sub objNewMailItems_ItemAdd(ByVal Item As Object)
    If Item.Class <> olMail Then Exit Sub
    If (InStr(Item.SenderEmailAddress, "@")) Then
        Set objProp1 = Item.UserProperties.Add("Ext", olYesNo, True)
        objProp1.Value = True
        Item.Save
    End If
End Sub
 
Thank you and yes, the icon field looks better. :)
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
K can't get custom form to update multiple contacts using VBA Outlook VBA and Custom Forms 3
R Custom Contact Form how to update when loaded. Outlook VBA and Custom Forms 6
Cameron Piper Automatically update custom forms across multiple computers Outlook VBA and Custom Forms 1
S Send Update of Custom Appointment Form Using Outlook 2
P Can no longer sync Outlook with iPhone calendar after iPhone update to 17.1.1 Using Outlook 7
M "Attachment Detacher for Outlook" add in, does it update the server copy of the email? Using Outlook 1
icacream New password won't update Using Outlook 2
Commodore Safe way to add or update holidays; Windows Notifications issue Using Outlook 8
O Batch update calendar Using Outlook 3
R Outlook 365 update sets delete from server flag Using Outlook 1
P Outlook 2019 UI changes after 20H2 update Using Outlook 1
D Change Microsoft Account password - what to do to update on all devices Using Outlook 4
B Outlook 2016 Retail C2R keeps logging since update? Using Outlook 0
C Not sync folders not found after MS Outlook 365 update Using Outlook 1
W September 2020 - No Default Email Client message after Office Update Using Outlook 1
D.Moore VBA script fail after Office 365 update Using Outlook 8
W April 2020 Office 365 Update - Add-Ons fail after Office 365 Update Using Outlook 6
M Outlook 2010 Problem with OutLook 2010 32 bit, after Windows Auto Update Using Outlook 3
Jennifer Murphy Grant R/W (update) access to a friend Using Outlook 3
L Favorites don't update Using Outlook 1
F Copy and replace not update contact in another pst Using Outlook 0
M Message list font changed after update Using Outlook 2
M Quicken One Step Update Bill Reminders Not Syncing to Outlook Using Outlook 1
O Windows 1803 update : QAT and toolbar changed, language pack gone... Using Outlook 5
J Updating existing entry on shared calendar wants to send update from delegate Using Outlook 0
N Using email notification to update calendar events? Outlook VBA and Custom Forms 4
K Update Appointment category when changed in Excel Using Outlook 3
V Outlook 2003 problem with Windows 10 Creators Update 1709 Using Outlook 0
G Windows Update Causes BCM Database Access Problem? BCM (Business Contact Manager) 4
K Update subject based on text in body Outlook VBA and Custom Forms 3
A Creating Progress Bar or Status Bar Update Outlook VBA and Custom Forms 0
M Recent Update Did not Fix Search Problems Using Outlook 7
C Update Notes for Meeting Attendees Using Outlook 8
A Attendee Update Outlook Meeting Invite Using Outlook 0
Diane Poremsky Outlook Email Security Update Using Outlook 0
S Task Update coming as email and not updating task Using Outlook 3
Diane Poremsky Remove Office 2013 Update Banner Using Outlook 0
B IMAP folders don't update when Outlook 365 opens Using Outlook 0
J Outlook Macro to Update Sharepoint Excel File Using Outlook 1
Diane Poremsky Task Request Status Update Address Missing Using Outlook 0
CWM550 Importing from Eudora Update Using Outlook 5
M Update field codes when opening Outlook Template Outlook VBA and Custom Forms 2
Bachelle Macro to Update Existing Task from New Email Outlook VBA and Custom Forms 3
I Microsoft Security Update KB3097877 Using Outlook 14
S Outlook 2010: October 2015 Update Using Outlook 0
S Outlook 2013: October 2015 Update Using Outlook 0
Diane Poremsky Update Contacts with a New Company Name and Email Address Using Outlook 0
Diane Poremsky Update Contacts with a New Company Name and Email Address Using Outlook 0
F Update the notes field Exchange Server Administration 0
A BCM crashes after Windows 10 update BCM (Business Contact Manager) 1

Similar threads

Back
Top