Updating Contacts In Outlook 2013

I am using this script to update the Display as field for my Outlook Contacts.  (I got the script from:  http://www.slipstick.com/outlook/contacts/bulk-change-outlook-contacts-email-display-name-format/ )  

It works great for my contacts in my local contact folder.  I want to run this script against contacts in a Public Folder Contact List.  I'm not sure how to do it.  Can someone help?  


Public Sub ChangeEmailDisplayName()
    Dim objOL As Outlook.Application
    Dim objNS As Outlook.NameSpace
    Dim objContact As Outlook.ContactItem
    Dim objItems As Outlook.Items
    Dim objContactsFolder As Outlook.MAPIFolder
    Dim obj As Object
    Dim strFirstName As String
    Dim strLastName As String
    Dim strFileAs As String
 
    On Error Resume Next
 
    Set objOL = CreateObject("Outlook.Application")
    Set objNS = objOL.GetNamespace("MAPI")
    Set objContactsFolder = objNS.GetDefaultFolder(olFolderContacts)
    Set objItems = objContactsFolder.Items
 
    For Each obj In objItems
        'Test for contact and not distribution list
        If obj.Class = olContact Then
            Set objContact = obj
 
          With objContact
     
          If .Email1Address <>"" Then
            ' Uncomment the  strFileAs line for the desired format
            ' Add the email address to any string using
            ' the following code:
            ' & " (" & .Email1Address & ")"
                 
             'Firstname Lastname (email address) format
             ' strFileAs = .FullName & " (" & .Email1Address & ")"
                 
             'Lastname, Firstname format
              strFileAs = .LastNameAndFirstName
                 
             'Company name (email address) format
             ' strFileAs = .CompanyName & " (" & .Email1Address & ")"
                 
             'Comapany Firstname Lastname (email address) format
             'the display name will have a leading space if
             'the contact doesn't have a company name
             'strFileAs = .CompanyName & " " & .FullName & " (" & .Email1Address & ")"
                 
 
 
             'File As format
             'Does not support Company (Fullname) format.
             'Only Company name is used in the display name
             'strFileAs = .FileAs
                 
             .Email1DisplayName= strFileAs
 
             .Save
           End If
          End With
        End If
 
        Err.Clear
    Next
 
    Set objOL = Nothing
    Set objNS = Nothing
    Set obj = Nothing
    Set objContact = Nothing
    Set objItems = Nothing
    Set objContactsFolder = Nothing
End Sub
mschiradAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mschiradAuthor Commented:
I got it:  I checked the site further and it had an example.  Thanks to slipstick.com!
Public Sub ChangeFileAsSelectedContacts()
    Dim Session As Outlook.NameSpace
    Dim currentExplorer As Explorer
    Dim Selection As Selection
    Dim currentItem As Object
    Dim folder As Outlook.folder
     
    Dim obj As Object
    Dim strFirstName As String
    Dim strLastName As String
    Dim strFileAs As String
 
    Set currentExplorer = Application.ActiveExplorer
    Set Selection = currentExplorer.Selection
 
    On Error Resume Next
 
    For Each obj In Selection
    Set folder = currentItem.Parent
        'Test for contact and not distribution list
        If obj.Class = olContact Then
            Set objContact = obj
 
            With objContact
            ' Uncomment the  strFileAs line for the desired format
 
                'Lastname, Firstname (Company) format
                ' strFileAs = .FullNameAndCompany
                 
                'Firstname Lastname format
                 strFileAs = .FullName
               
                'Lastname, Firstname format
               '  strFileAs = .LastNameAndFirstName
               
                'Company name only
                ' strFileAs = .CompanyName
               
                'Companyname (Lastname, Firstname)
                ' strFileAs = .CompanyAndFullName
                 
               .Email1DisplayName = strFileAs
 
                .Save
            End With
        End If
 
        Err.Clear
    Next
 
    Set Session = Nothing
    Set currentExplorer = Nothing
    Set obj = Nothing
    Set Selection = Nothing
    Set currentItem = Nothing
    Set folder = Nothing
End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Outlook

From novice to tech pro — start learning today.

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.