How To set your "File As" format to be uniform in Outlook Contacts

The problem with entering contact information on your Phone and Outlook and anything else that may be syncing with your contacts is that a lot of the time you end up with information they may not be entered in a uniform way.  The File As attribute is often one of these problems where some contacts are filed as "First Last" while others are filed as "Last, First".  The steps below will hopefully help you setup Outlook so it is uniform across all your contacts.

Step 1. Set Outlook to default to your preference.

  • In the Outlook Menu: Go to Tools -> Options -> Contact Options -> Set the Default "File As Order"

Step 2. Setup Security on Outlook to Allow for Unsigned Macros

  • In the Outlook Menu: Go to Tools -> Options -> Macros-> Security
  • Change the Security to "Warnings for All Macros"
  • Restart Outlook

Step 3. Installing the Code

  • In the Outlook Menu: Go to Tools -> Options -> Macros-> Visual Basic Editor
  • In the Left hand window double click on "ThisOutlookSession"
  • When a new windows titled "VBAProject.OTM - ThisOutlookSession" paste the following in:

Public Sub ChangeFileAs()
    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
                strFirstName = .FirstName
                strLastName = .LastName
                strFileAs = strFirstName & " " & strLastName
                .FileAs = strFileAs
                .Save
            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

Step 4. Saving the Code and Running the Macro

  • After you have pasted the code above into the windows titled "VBAProject.OTM - ThisOutlookSession" Click on File -> Save
  • Close the Visual Studio Window
  • Go to your Contacts Windows
  • Click on the Contacts Folder in Outlook
  • In the Outlook Menu: Go to Tools -> Options -> Macros
  • Select "ThisOutlookSession.ChangeFileAs" and Click on Run
  • After a about a minute depending on the number of contacts you have they will all be edited to display Contacts in the way you want.

Step 5. Change Security on Outlook back to not allow for Unsigned Macros

  • In the Outlook Menu: Go to Tools -> Options -> Macros-> Security
  • Change the Security to "Warnings for signed Macros, all other Macros are disabled"
  • Restart Outlook

Notes:

  • To change the order of strLastName and strFirstName to change the File As. You can either use ", " or just a space: " " between the names in the highlighted part of the code.
  • This code works only on the default contacts folder.

Credits:

The Sample code used here was obtained from the FileAs VBA Code sample from Slovaktech.