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
peakpeakAsked:
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
    olkView.Save
    Set olkView = Nothing
End Sub

Open in new window

0
 
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?
0
 
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
0
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 !
0
 
David LeeCommented:
Thanks and you're welcome.  Always happy to help out.
0
 
peakpeakAuthor Commented:
Works like a charm now ... great brain BDF ....
0
 
David LeeCommented:
Thanks!  You're too kind.
0
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.