Insert custom field in Outlook Contact List through VBA

I can add a custom field to the Field Chooser:
Set objContactsFolder = Session.GetDefaultFolder(olFolderContacts).Folders("Test")
objContactsFolder.UserDefinedProperties.Add "Testing", olYesNo

How do I insert it into the contact folder heading (field) with VBA?
LVL 28
Who is Participating?
David LeeConnect With a Mentor Commented:
Assuming that you know the name of the field and that you want to add it to the current view, then this will do it.
Sub AddFieldToView()
    Dim olkView As Outlook.View
    Set olkView = Application.ActiveExplorer.CurrentView
    With olkView
        'On the next line edit the name of the field you want to add'
        .ViewFields.Add "Some_Field_Name"
    End With
    Set olkView = Nothing
End Sub

Open in new window

David LeeCommented:
Hi, peakpeak.

I'm not clear on the question.  Are you asking how to modify the view so it shows this field?  If so, what version of Outlook are you using?
peakpeakAuthor Commented:
Yes, instead of opening the Field Chooser and drag the field in question to the headers and drop it where convenient I like to do that in VBA, OL 2007
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

peakpeakAuthor Commented:
Encountered some errors but essentially it worked. Thank You BlueDevilFan. You're the man !
David LeeCommented:
Thanks and you're welcome.  Always happy to help out.
peakpeakAuthor Commented:
Works like a charm now ... great brain BDF ....
David LeeCommented:
Thanks!  You're too kind.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.