Bulk Change File As Format for Contacts

Last reviewed on December 30, 2013   —  106 comments

Applies to Microsoft Outlook 2013, 2010, 2007, 2003, 2002, 2000

I call this my "super-duper bulk contacts changer" code because it's so easy to modify to use with other contact fields. Customize the code yourself or use the "Bulk change Contacts" VBA samples at Move Phone Numbers to a Different Phone Field and Change Email Display Name Format. Want to change the FileAs field in all contacts to match the setting in Options? I have a macro for that too: Change FileAs format to match Outlook's default setting. If the first and last names are in the wrong fields, use this macro to swap them: Swap First and Last Name Fields

To change the default File As format used for new contacts, go to Tools, Options, Contacts options in older versions or File, Options, Contact options in Outlook 2010 and 2013.

Change the default format in Contact Options

Outlook's Contact's offer a number of File As formats and this format can be used for the contact's name display in the Address Book. However changing the File As format on a large number of contact's is time-consuming when you need to change the contacts one by one. You can do it using VBA or a utility (listed below).

Change the FileAs format in Outlook's Contacts

The file as format options are shown in the screenshot. The VBA code sample supports all 5 formats.

Along with changing the File As order, you can change the order Outlook assumes you use when you enter the name. This setting determines how the names populate the dialog when you press the Full name button. If the name order is wrong in FileAs ("Mary, Smith" when using last, first format), check this setting. If you choose Last First format you don't need to use a comma to separate the names when you enter them and First Last1 Last2 correctly puts the name in the middle position into the last name field, not the middle name field. Outlook will detect names separated by commas as Last, First format, regardless of the Fullname format setting.

VBA Sample

The following code sample supports all 5 File As formats available in Outlook. Press Alt+F11 to open the VBA editor then copy and paste into ThisOutlookSession. Uncomment the strFileAs line that uses the format you desire before running it. (Uncomment the line by removing the apostrophe from in front of the strFileAs = [name_format] command you wish to use.)

See page 2 (or the text file below) for code sample 2 to change the FileAs format on selected contacts. (Tested in Outlook 2010.)

To test for a value (such as Company name) and use a different File As format if the value is empty, you need to use an If... Then statement.

            With objContact
                If .CompanyName = "" Then
            ' Firstname Lastname format
                   strFileAs = .FullName
               Else
            ' Company name only
                   strFileAs = .CompanyName
               End If
               .FileAs = strFileAs
               .Save
            End With

See Bulk change FileAs format to match Outlook's default setting for a version of this macro that reads the default setting in the registry and applies it to existing contacts.

Run Macro button or press F5To use, select the Contacts folder in Outlook then return to the VBA Editor and press the Run button or F5 to run the macro. You can run the macro later by pressing Alt+F8 (after selecting the Contacts folder) then choosing the macro and pressing Run.

To help eliminate errors, we have text files containing the VBA code samples available. To use, open the text file and Select all (Ctrl+A), copy then paste into the VBA editor. To save to your computer, right-click and choose 'Save Target as'.
Original code - change contacts in default folder | Change selected contacts in any folder

Public Sub ChangeFileAs()
'From http://slipstick.me/5z
    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
            ' Uncomment the  strFileAs line for the desired format
            ' Comment out strFileAs = .FullName (unless that is 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
                
               .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

Test for Names and Company

If you have a mix of contacts for people, with a value in the Fullname field, and companies, where the Fullname field is blank, you can replace the With objContact... End with code block with the snippet below.

This code checks for a value in the fullname field and if it's blank, it looks for a company name. If a value is in the company name field, it's used in the FileAs field.


            With objContact
             ' Test for blank name field
             If objContact.FullName = "" Then
                If objContact.CompanyName <> "" Then
                   .FileAs = .CompanyName
                End If
             Else
                .FileAs = .FullName
             End If      
             .Save
            End With

Change Mailing address

If you need to switch the mailing address to the business address field (or from business to home address) you can check for a value in the business address field, and if not blank, copy it to the .MailingAddress field.

Use .HomeAddress if you want to make the home address the mailing address.

As with the code above, replace the With objContact... End with code block in the macro with the snippet below.

            With objContact
               If .BusinessAddress <> "" Then
                 .MailingAddress = .BusinessAddress
                 .Save
               End If
            End With

Customize the code

I call this code sample my "super-duper bulk contact changer macro" because it's so easy to change it to work on other Contact fields. Simply replace section in the original macro that changes the FileAs field with other fields.

For example, changing it to .Body = "" will erase text from the body, solving a problem Nox had syncing contacts to a smart phone. If the phone can handle some text, you could keep some of the text, replacing 1024 with the number of characters you want to keep.

      ' keep some text 
               .Body = Left(.Body, 1024)

 If obj.Class = olContact Then
        Set objContact = obj

            With objContact

      ' erase the entire body
               .Body = ""

               .Save
            End With
End If

Common Errors

Colors when the code is correct
After pasting the code into the VB editor, the colors should be similar to the colors in this screenshot (and as seen in the code sample above).

Any text shown in Red has an error in it.

Blue, Black, and Green are "good", with the Blue color indicating VBA commands (If, Then, End etc), Black is your variables, and Green is used for comments. The second line in one of the 5 sets of Green lines needs to have Black text. You do this by removing the apostrophe (') from in front of the line. If more than one of those 5 lines is black, add an apostrophe to front of the format line you don't want to use. (In my screenshot, the second set is the format I want to use.)

Continue to Code Sample 2: Change the contacts in the selected folder

Change only the 'subject' field used by the Address book

Note: this was written for an older versions of Outlook and is not needed with new versions.

Use the Outlook File As Order custom form to change just the display in the Address book, from Last name first, to First name first or use the File As entry.

Notes:

  • This method will not change the actual sort order in the Contacts folder or format used on the File As field.
  • Will return an error if there are distribution lists in the Contacts folder.
  • This has the same options as you'll find in Tools, E-mail Accounts, View or change existing Address books, Outlook Address book properties, but also adds Last name first option and full File As format, including the Company name.
  • Works on any contact folder - select the folder before clicking Run in the VB Editor or pressing F5. Leave the editor open and select another folder to use it on additional folders.

Tools

ContactGenie Toolkit

ContactGenie Toolkit: 28 functions for Outlook 2000-2010 enabling changes to individual standard and custom fields; standardization for Message Class, CompanyName, FileAs, EmailDisplayAs, Fullname, and other fields; contact and NK2 info export; export contacts to CSV file; global changes for CompanyName, Company Address, Email and Web addresses. Preview/override any pending changes. Add Birthday/Anniversary/user-defined dates to default calendar. Personal Distribution Group management and more.

Written by

Diane Poremsky
A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

Please post long or more complicated questions at Outlookforums.

106 responses to “Bulk Change File As Format for Contacts”

  1. Jan Kuyl

    This is the script I havge been looking for.

    I ran the VBA script in Outlook 2007 to change the FileAs property of all my contacts to "Firstname Lastname", with partial success. All contacts with a title (Mr. or Mrs.) kept their old display property, meaning "Smith, John" became "John Smith", but "Mr. Ferguson Alex" did not change.

    Is there an updated version/fix for this script available?

  2. Robert

    Works with Outlook 2010 SP1. Haven't tested with anything other than .FullName, but it served it's purpose. Thanks for the script!

  3. Yakira

    I'm not used to doing any of this stuff but input the script as explained. How do I actually run it? What do I do after pasting it into VBA?

  4. Jeff

    Need some help. I am getting an "Compile error: Expected End Sub" error. I do not have any distribution lists in my contact folder.

    I pasted the code into VBA under ThisOutlookSession.

    Went back to Outlook and have selected the contact folder and also tried to select all contacts in the folder.

    I keep getting this error any suggestions? I feel that maybe I am not selecting the contact list correctly.

    After I clear the error, the ver first line "Public Sub ChangeFileAs () is highlighted in yellow with a yellow arrow to the left of it.

  5. J Lewis

    I have more than one contacts folder (suppliers, as well as contacts, which is customers and personal contacts). If I select the one (suppliers) I want to update, it does not update it. Any ideas? Can I change the "set" references in the script to "suppliers" where "contacts" currently appears?

  6. J Lewis

    it may be something I did, but i got a syntax error. I copied into the editor after alt-f11.

    i copied from "public...

    to

    ...end sub"

  7. J Lewis

    Oddly enough, (no error after pasting the text), but instead of changing "file as" to [company (last, first)] it erases the "file as" field. Not on all the contacts, but the contact I have selected in outlook, in the background. If nothing is selected, nothing is changed.

    Thanks for the help by the way, even though I haven't been able to knock this out yet.

    I'd do this by hand, but there are 920 vendors in my outlook. Thanks again for any help.

  8. J Lewis

    I did not remove any apostrophes. Pasted it as it was in the text file.

  9. J Lewis

    I deleted the '. Sorry I didn't know what that meant. Newbie to this stuff.

    FYI, it only worked when a record was selected. Therefore, I had to select the records within my contacts folder to make it work.

    OL 2007 (12.0.6562.5003) on Win 7x32

    Thanks for the help!

  10. Rae Ann

    Can you tell me how to display the Notes section on the address book? One of my staff really wants to see her notes when viewing the address book. Is this possible in Office 2010?

  11. Justin

    I am getting a "Compile error: Expected End Sub" error as well. I downloaded the text file and pasted from that, and it isn't working. When I get that error the first line is highlighted in yellow and "objContact =" from

    If obj.Class = olContact Then

    Set objContact = obj

    is highlighted in blue.

    Thanks!

  12. Ray

    Worked brilliantly! Thanks!

    Is there any way to change the File As to First Name Last Name (Company)? Other than manually, that is.

  13. Ramon

    I don't use the default Outlook Contacts Folders, but iCloud. I guess the following line needs to be changed:
    Set objContactsFolder = objNS.GetDefaultFolder(olFolderContacts)
    question is, how do I identify the name of the icloud contacts Folder?

  14. Nicu

    Thank you, easy to set up. Just after I copied the script there were two errors, but copying it from the link you provided in comments it worked.

  15. Taqi

    Thanks for this Diane! So I installed the VBA but when running, the "play" icon is not highlighted it seemingly does nothing. When it is running (I think) and when I click on the shortcut in the outlook after highlighting the contact, it erases the whole "File As" field.

    My question is: How do I use this macro?

  16. Ciaran

    Magnificent - found this VBA "how to" and reorganised 1076 contacts within less than 5 minutes!
    thanks

  17. PeterB

    I feel that I'm so near to what I need, but can't quite finish off - can you assist?

    I'm following the "Change only the 'subject' field used by the Address book" instructions above, but fail at the "Usage" paragraph in the ReadMe file - I don't see the 3 buttons! I simple want the sort order in the address book to be the same as the values in the FileAs Field, ie Subject Field = FileAs.

    I'm using Outlook 2010 on a standalone Windows 7 PC (ie no exchange server).

    The form reads as if this is a one off, bulk conversation - is there script to set this as the permanent option for all new/amended contacts?

    Thanx, Pete

  18. Markos

    Hi all,

    really useful vba macro indeed.

    I have an additional problem and was wondering if anyone has solved it before:

    At the office we have been inputting the First and Last Name in the wrong order - meaning that Outlook was set up to expect First Last in the Fullname field while we were putting Last First. Now more thatn 1000 contacts have the wrong order in the Fullname field. Is there a VBA for a bulk change (order reverse)?

    Thanks,

    Markos

  19. Armin

    Hello,
    thank you! the change File As for default folder worked perfect.
    I do have other contact folders that i was hoping to change the file as, so i selected the contact folder, went to VBA by pressing Alt+F11, paste the selected folder script but when trying to run i get an error:

    it highlights "folder As Outlook.folder" and pop ups the following error:
    Compile Error:
    User-Defined type not found

    i am using outlook 2003.

    can you help please?
    thanks

  20. Mike

    I could not get this to work. Let me give you how things are setup in my system.
    I am running Win 7 and Outlook 2010.
    I am connected to an exchange server so I do not have a pst file, instead on pc is an ost file.
    I have 24 contact folders all with unique names under My Contacts
    When I run the script I get the following error
    Compile error:
    Syntax error
    The script stops at Firstname Lastname format
    I have removed the ' from both the Firstname Lastname format line and the strFileAs - .FullName
    Can you advise me on what to do next?
    Thanks

  21. Simon

    Forever in your debt, Diane, works flawlessly.

  22. Edwin

    Needed to add "Sub" to end last line but worked great.

    Thanks a million Diane. Saved me so much time. :)

  23. Paddy

    Thankyou Diane this is brilliant. I have used both VBA for Display as ans File as. Very nice and convenient. Pitty it choices aren't available in contacts as a default.
    Thanks

  24. Nathan

    Thanks!

  25. Paul Nocero

    I added the following three lines after the .FileAs= line to update the way e-mail addresses are displayed, to make them consistent with the contact name:

    ' Set "Display As" name in Contact folder

    If .Email1Address "" Then .Email1DisplayName = .FileAs & " (" & .Email1Address & ")" Else .Email1DisplayName = ""
    If .Email2Address "" Then .Email2DisplayName = .FileAs & " (" & .Email2Address & ")" Else .Email2DisplayName = ""
    If .Email3Address "" Then .Email3DisplayName = .FileAs & " (" & .Email3Address & ")" Else .Email3DisplayName = ""

  26. Bob May

    Thank You. Just what I was looking for. Worked perfectly. Thanks for sharing!

  27. Paul D

    I can't get this to work. I am on an Exchange server and the script prompts me for my Outlook credentials. I type in my logon password but it won't accept this and re-prompts. Is there a separate Outlook "credential"? I use the logon to access Outlook via a browser, although I almost never do this. Any help would be greatly appreciated. Thanks!

  28. Carl Bell

    I want to change the "Display as" from an Email address to a First name space Last Name.
    Can it be done?
    Carl

  29. Andrew

    This code worked great in Outlook 2010, just what I needed. Thanks very much

  30. nicolo

    hello everyone! i tried copy and pasting both vba codes. but i always get an error stating "macros in this project are disabled outlook 2010" i have no idea what to do next.
    i enabled the macro lowered security to medium then to low.
    i am using outlook 2010.
    can someone please help me?

  31. nicolo

    Hello Diane,
    just a quick question for you.
    I am trying to adapt your vba code to fix the file as of my outlook contacts.
    When i receive them from the icloud i get them with the file as field inverted (last, first)
    I followed your guide step by step and was able to fix that using the script on page 2 but i cannot seem to make the one on page 1 work.
    I'm guessing that the script on page 1 is for the default outlook folder and not for the icloud folder.
    Is there a way that i can change the name of the folder so that the icloud contact folder will be tageted?

  32. Andy

    Thanks - saved me loads of time!

  33. Tom Petrie

    Hi Diane,

    I'm fairly elliterate. I've just lost the IT guy who'd hold my hand and now I'm trying to fly solo. What I'd like to do is to re-organize all 3682 contacts in my 2010 Outlook so that they are filed by company name. I'm trying to follow your instructions step by step, but I'm stymied on Step One: Alt+F11 opens Send/Receive Groups, not the VBA Editor you reference. What to do?

  34. Tim Ponting

    Such a useful piece of code, many thanks. We use Title, Middle Name and Suffix fields for our own data purposes, not as Outlook intended, and by modifying this code a little it has allowed us to generate clean File As and Email Display Name fields automatically.

  35. Gary

    Thank you sooo much!!! Been battling with this as I used excel to clean up all the contacts and then imported them back only to find the "file as" a mess. It messed with the way contacts were displaying in my phone too
    Thanks again!

  36. Harry

    Don't come round here...I'll have to give youd a big tongue kiss. Thankfully I was smart enough to do a search before changng 750 contacts one at a time. Kudos to you!

  37. mayur

    Hi, Diane

    I also looking for same thing, but my concern is that, i want to detect which default format user has set for File As field.

    Once it conforms then only again ask him to change it or not..!!

    can please help me on this..!

  38. David Tabor

    The code ran fine and changed all to the format I wanted (Lastname, Firstname)but seconds after changing it reverted back to Fullname. Not sure what I'm doing wrong.

  39. Sean Woodley

    WOW, AMAZING ... you have saved me hours of re-doing my contacts after my phone sync deleted everything!

  40. Rob

    I ran this for a client. it worked great on 3118 contacts, Thank you!
    I was wondering if it is at all possible that this could have created duplicate contacts? client is complaining of multiple contacts. not all but quite a few.

    Please let me know

  41. Julia

    As I have never done/heard of VBA before, it took me a while to figure out that I have Microsoft Outlook open at the same time as the VBA. I had to guess to click on all the directory levels to get to ThisOutlookSession, then copied and pasted the code into VBA. I selected each of my address lists, then went back into VBA/This session, and pressed F5. Another box came up with Run, so I chose Run. I then closed out Outlook, but my Display As still shows as email addresses, not the person's name. Have I missed something? I am almost completely at a loss. Thanks for any further help you can give me.

  42. steve s.

    i use Outlook 2010 and am having trouble finding the "this outlook session" you reference. when i hit ALt + f11 i see the VBA but what do i click on to open a window into which i can paste your code? i see reference to left pane, but can't find the 'This Outlook Session' within. thanks.

  43. steve s.

    thanks for quick reply. i wonder if in clicking on different things to try and figure this out, i now messed up something. now saying macros are disabled?? thanks.

  44. jaydr

    Not a vba expert and I'm having the same problem as the first commentor, with the Titles (Mr, Mrs etc) winding up in the file as field. Is there a way to alter the code so that it is set to FirstName LastName instead of FullName (which I guess includes the titles)?

    Thanks for your help. This otherwise is terrific for me.

  45. Julia

    I'm still not getting Display Name as Smith, J. It shows the email address on most of them (presumably the ones not imported from Outlook Express). The Name column shows correctly. Any ideas, please and thanks? (I don't know how to use all this Visual Basic stuff and what I did try from above obviously didn't work.) I hope I don't have to go and change each one individually--there must be about 500 names.

  46. Eric Harper

    Awesome fix!! Saved me hours fixing what shouldn't have been broken in the first place.

  47. Howard Bachtel

    I would like to have the Address Book display the name and e-mail only (omit the column "Display Name" as it is redundant. This area looks like an option but I don't see this specifically. I am not proficient at VBA but have used it some. Can you give me any advice?

    Thank you in advance.

  48. Jawad

    All my file as area is now blank after using this macro. Partially worked (removed all file as data) but didnt add the new file as data.

  49. Val

    Diane,
    It worked but i forgot to Uncomment the strFileAs line that uses the format i wanted , and your code was set to
    :

    'Lastname, Firstname format
    ' strFileAs = .LastNameAndFirstName

    I needed:

    'Firstname Lastname (email address) format
    strFileAs = .FullName & " (" & .Email1Address & ")"

    Now all the names display as last name, first name format .
    When i past the code again and run , it gives me an error message ::
    The macros in this project are disabled. Please refer to the online help or doscumentation of the host application to determine how to enable macros.

    Any ideas ?
    Thanks in advance,

    Val

  50. Aaron Crews

    Will this work in Outlook 2013 (365)? Thanks, Aaron

  51. Kendra Von Achen

    genius! It worked! I recently synced my contacts between 3 different programs, including Outlook and it messed up most of my File As formats. I ran your code across all of my contacts and it fixed it! Thank you so much for sharing this!!!

  52. Kuba

    Thanks so much! I have just run it on Outlook 2003. I was so annoyed with changing the order manually.

  53. Wrong Passport

    Thank you! I had been annoyed with this problem for years; I finally decided to do something about it and there was your solution

  54. kennyb7

    Does this work with Outlook 2013?

  55. MTran

    Thanks very much. Worked perfectly and has saved me the mundane approach of having to change individual contacts.

  56. wallrats

    Great Script works flawlessly on the "default" contact list.. Is it possible to modify the script to run against a non-default Contact List. I have a few contact list for different groups of people. I have the following list titled: Contacts, Manufacturing USA, Manufacturing EUR, Sales USA, Sales EUR. Any help would be greatly appreciated..

  57. Breanne Miller

    The Macro worked; however, the company is not listed between parenthesis. How can i fix this? I'd like it to appear as: Last, First (Company)

  58. STGdb

    Nice script Diane, thank you very much. I know that the thread is old but it still works.

    Also, for anyone who is interested, your not stuck with using just the standard five selections that Microsoft provides in Outlook. Just place a comment character in front of the line:

    strFileAs = .FullName

    ...and below the line you just added a comment character to, add:

    'Configure FileAs to be Company Name (Full contact name)
    strFileAs = .CompanyName & " (" & .FullName & ")"

    Or you can the same results as the above line with something like:

    'Configure FileAs to be Company Name (Full contact name)
    strFileAs = .CompanyName & " (" & .Title & " " & .FirstName & " " & _
    .MiddleName & " " & .LastName & " " & .Suffix & ")"

    The benefit about the latter of the two examples above is that you can remove just the contact's Title or their Suffix or you can change the character that encloses the contact's name.

  59. Dave O

    This worked perfectly in Outlook 2013. Thank you so much for taking the time to post these detailed instructions.

  60. EIKAinc

    Hi Diane!

    I am not VB expert, but I need a little bit different script. I need to re-arrange Full Name column, not File As column. Now when I import data to Outlook 2013 from iCloud, names appear as FirstName LastName, but I need LastName FirstName (and no comma between). And I do not use FileAs column at all (it contains data, but it's hidden).

    Could you please change script to satisfy my requirement?

    Thanks!

  61. EIKAinc

    Thanks! It works, just required double run. First run have no effect in my Outlook 2013.

  62. TLMS

    What is a comment character?

  63. simonjhudson

    Brilliant - this issue was beginning to really hurt me as CRM keeps updating stuff without regard to my preferred order.
    Thanks !!

  64. Dale

    To change the mailing address to .BusinessAddress I used:
    SelectedMailingAddress = 2

    ...because
    .MailingAddress = .BusinessAddress simply copied the address information from .BusinessAddress to .HomeAddress (which was the defaulted .MailingAddress).

  65. john

    Hi Diane I have a strange behaviour when importing a bulk contacts csv file, while having selected the First, Last (both in address book and Options/People) I get a contacts' appearance in the first column (File As) which is First, Last, Company (!). I tried running your script on the selected contacts folder with the .Firstname parameter selected but all I got is the same result. Any ideas are welcome because this is already driving me crazy. =)

Leave a Reply

If the Post Coment button disappears, press your Tab key.