Condividi tramite


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.

Comments

  • Anonymous
    October 17, 2007
    Whenever I create a new contact on my pda, it default to "last name, first name", would it be possible to change the default setting to 'first name last name"?

  • Anonymous
    December 26, 2008
    This is FANTASTIC! I have been searching for something like this for years and have found no good solutions. Frankly, this shouldn't be necessary because MS should have something for it... Thank you so much!

  • Anonymous
    August 18, 2010
    Thank you! This worked perfectly in Outlook 2007!  Very silly that Microsloth hasn't built this into Outlook.

  • Anonymous
    April 14, 2011
    This was very helpful! Thank you very much. One correction. In my Outlook the Macro is not under Options. It's Tools -> Macros-> Security

  • Anonymous
    June 01, 2011
    My File As cannot be changed.  Outlook 2007 bug.

  • Anonymous
    June 23, 2011
    Fantastic! This saves so much effort! My only qualm is the same as Patrick's!

  • Anonymous
    July 06, 2011
    The comment has been removed

  • Anonymous
    September 17, 2011
    Wow that is really great. Thanks a lot!

  • Anonymous
    November 20, 2011
    I didn't work for me, said there is an error!!! I agree that we shouldn't have to find a fix, microsoft should incorporate this sort of fix.

  • Anonymous
    November 19, 2012
    Worked perfect for me in Office 2007. Thanks for posting this. Only corrections are look for the macros under Tools > Macros

  • Anonymous
    May 28, 2013
    Hi, I used in Outlook 2010. Some options are in a different place, but worked like a charm. Saved me from spend some bucks. Thanks.

  • Anonymous
    November 02, 2013
    Fantastic! So pleased to finally have everything in order again! Thank you!

  • Anonymous
    August 31, 2014
    Really helpful and the instructions are really easy to follow. Thanks

  • Anonymous
    September 04, 2014
    The comment has been removed

  • Anonymous
    April 01, 2015
    All of my contact Home addresses, were changed to Business Address. 1600 + contacts to change. Not good.

  • Anonymous
    April 17, 2015
    MS Outlook 7 - If I click on Visual Basic Editor (Step 3) it gives me error message "'VBE6EXT.OLB' could not be loaded". Please help!