Bulk Change File As Format for Contacts

Xavier Mustin

Staff member

/ Outlook / Contacts / Bulk Change File As Format for Contacts
Last reviewed on December 30, 2013
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.
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).
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
' Company name only
strFileAs = .CompanyName
End If
.FileAs = strFileAs
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.
To 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'.
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
End With
End If
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
.FileAs = .FullName
End If
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
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 Noxhad 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 = ""
End With
End If
Common Errors
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.
  • 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.