• Outlook User
  • New Outlook app
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
  • Developer
  • Microsoft 365 Admin
    • Common Problems
    • Microsoft 365
    • Outlook BCM
    • Utilities & Addins

Bulk Change Contact's FileAs Format to Match Outlook's Default Setting

Slipstick Systems

› Developer › Bulk Change Contact’s FileAs Format to Match Outlook’s Default Setting

Last reviewed on January 16, 2019     40 Comments

Change the FileAs format in Outlook's ContactsThis version of the Bulk Change File As Format for Contacts macro checks the registry for the user's default FileAs format and offers to change it. It then updates the contacts in the default contact folder to use the default FileAs format.

It's not the cleanest code, but it works in all versions of Outlook and gets the job done.

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 strFileAs As String
    Dim myRegKey As String
    Dim myValue As String
    Dim myFileAs As String
    Dim myAnswer As Integer
    
On Error Resume Next

  ' get registry key to work with
  ' change the Outlook version # to match your version
  myRegKey = "HKEY_CURRENT_USER\Software\Microsoft\Office\15.0\Outlook\Contact\FileAsOrder"
  If myRegKey = "" Then Exit Sub
  'check if key exists
  If RegKeyExists(myRegKey) = True Then
    'key exists, read it
    myValue = RegKeyRead(myRegKey)
    If myValue = 14870 Then myFileAs = "Company"
    If myValue = 32791 Then myFileAs = "Last, First"
    If myValue = 32792 Then myFileAs = "Company (Last, First)"
    If myValue = 32793 Then myFileAs = "Last, First (Company)"
    If myValue = 32823 Then myFileAs = "First Last"
   
    
    'display result and ask if it should be changed
    myAnswer = MsgBox("The registry value for the key """ & _
               myRegKey & """is """ & myFileAs & vbCrLf & _
               "Do you want to change it?", vbYesNo)
  Else
    'key doesn't exist, ask if it should be created
    myAnswer = MsgBox("The registry key """ & myRegKey & _
               """ could not be found." & vbCr & vbCr & _
               "Do you want to create it?", vbYesNo)
  End If
  If myAnswer = vbYes Then
    'ask for new registry key value

    myValue = InputBox("Please enter new value: " & vbCrLf & _
    "14870 = Company" & vbCrLf & _
    "32791 = Last, First" & vbCrLf & _
    "32792 = Company (Last, First)" & vbCrLf & _
    "32793 = Last, First (Company)" & vbCrLf & _
    "32823 = First Last", myRegKey, myValue)
    If myValue <> "" Then
      RegKeySave myRegKey, myValue
      MsgBox "Registry key saved."
    End If    
  Else
  End If

' now that we've got the value of the default setting,
' we use it to set the value so all contacts are the same
    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 myValue = 14870 Then strFileAs = .CompanyName '"Company"
    If myValue = 32791 Then strFileAs = .LastNameAndFirstName '"Last, First"
    If myValue = 32792 Then strFileAs = .CompanyAndFullName '"Company (Last, First)"
    If myValue = 32793 Then strFileAs = .FullNameAndCompany '"Last, First (Company)"
    If myValue = 32823 Then strFileAs = .FullName '"First Last"

               .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

'reads the value for the registry key i_RegKey
'if the key cannot be found, the return value is ""
Function RegKeyRead(i_RegKey As String) As String
Dim myWS As Object

  On Error Resume Next
  'access Windows scripting
  Set myWS = CreateObject("WScript.Shell")
  'read key from registry
  RegKeyRead = myWS.RegRead(i_RegKey)
End Function

'sets the registry key i_RegKey to the
'value i_Value with type i_Type
'if i_Type is omitted, the value will be saved as string
'if i_RegKey wasn't found, a new registry key will be created
Sub RegKeySave(i_RegKey As String, _
               i_Value As String, _
      Optional i_Type As String = "REG_DWORD")
Dim myWS As Object

  'access Windows scripting
  Set myWS = CreateObject("WScript.Shell")
  'write registry key
  myWS.RegWrite i_RegKey, i_Value, i_Type

End Sub

'returns True if the registry key i_RegKey was found
'and False if not
Function RegKeyExists(i_RegKey As String) As Boolean
Dim myWS As Object

  On Error GoTo ErrorHandler
  'access Windows scripting
  Set myWS = CreateObject("WScript.Shell")
  'try to read the registry key
  myWS.RegRead i_RegKey
  'key was found
  RegKeyExists = True
  Exit Function
  
ErrorHandler:
  'key was not found
  RegKeyExists = False
End Function

How to use the macros on this page

First: You need to have macro security set to the lowest setting, Enable all macros during testing. The macros will not work with the top two options that disable all macros or unsigned macros. You could choose the option Notification for all macros, then accept it each time you restart Outlook, however, because it's somewhat hard to sneak macros into Outlook (unlike in Word and Excel), allowing all macros is safe, especially during the testing phase. You can sign the macro when it is finished and change the macro security to notify.

To check your macro security in Outlook 2010 and newer, go to File, Options, Trust Center and open Trust Center Settings, and change the Macro Settings. In Outlook 2007 and older, look at Tools, Macro Security.

After you test the macro and see that it works, you can either leave macro security set to low or sign the macro.

The macros on this page should be placed in a module.

Open the VBA Editor by pressing Alt+F11 on your keyboard.

To put the code in a module:

  1. Right click on Project1 and choose Insert > Module
  2. Copy and paste the macro into the new module.

More information as well as screenshots are at How to use the VBA Editor

More Information

More Bulk Change Contacts articles at Slipstick.com:
  • Bulk Change File As Format for Contacts
  • Bulk Move Phone Numbers to a Different Phone Field
  • Macro to Swap First and Last Name Fields
  • Show the Home Address on a Contact Form by Default
  • Update Contact Area Codes
  • Update Contacts with a New Company Name and Email Address
Bulk Change Contact's FileAs Format to Match Outlook's Default Setting was last modified: January 16th, 2019 by Diane Poremsky

Related Posts:

  • Read and change a registry key using VBA
  • Bulk Change Email Display Name Format
  • Bulk Change File As Format for Contacts
  • Use PowerShell to Bulk Change Contacts

About 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.

Subscribe
Notify of
40 Comments
newest
oldest most voted
Inline Feedbacks
View all comments

Timothy
January 8, 2024 8:24 pm

Thank you Diane! This saved a lot of time. Appreciate you sharing it. Blessings.

0
0
Reply
Martin Midgley
February 23, 2020 7:12 am

Thank you Diane; that's so helpful. I had to tweak the registry address from ""HKEY_CURRENT_USER\Software\Microsoft\Office\15.0\Outlook\Contact\FileAsOrder"" to "HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Outlook\Contact\FileAsOrder"" for Outlook 2007, but that's no big deal. What gets me though is that it was necessary in the first place. Perhaps there's someone at Redmond who goes by the unfortunate name of "Smith Comma Fred", but otherwise I think you'd have to go back to 19th century London to find people in the workplace referring to each other by their surnames. So why order the contacts by surname by default? Really odd.

0
0
Reply
Marty Sullivan
October 25, 2019 1:41 pm

Me again......Trying to apply macro to new Office 365. Keep getting the error "User-defined type not defined". Beow is what is highlighted.

Public Sub ChangeFileAs()
Dim objOL As Outlook.Application

0
0
Reply
Marty
February 6, 2019 10:00 am

Update.....all set....

Marty

0
0
Reply
Marty
February 6, 2019 9:46 am

Hello,

I have used this code on my personal laptop and it worked fine. I am now trying to use it on my work laptop and I keep getting the prompt to choose a macro, but none are listed.

Any ideas?

Marty

0
0
Reply
Diane Poremsky
Author
Reply to  Marty
February 6, 2019 11:10 am

Do you have macro security set to allow it and the macro project properly signed if using allow signed macro only?

0
0
Reply
Marty Sullivan
August 12, 2018 1:16 pm

So sorry to ask, but I forgot how to actually apply the code?

0
0
Reply
Diane Poremsky
Author
Reply to  Marty Sullivan
August 14, 2018 12:11 am

Alt+F11 to open the editor, paste the code into a module or thisoutlooksession then click Run.
This macro runs on all of the contacts in the default contacts folder.

0
0
Reply
Robert L
March 11, 2018 1:02 pm

I forgot to block it as code..... (remove my previous comment)

strFileAs = .FileAs  'Keep as is if no conditions are met

                If myValue = 14870 Then strFileAs = .CompanyName '"Company"
                If myValue = 32791 Then strFileAs = .LastNameAndFirstName '"Last, First"
                If myValue = 32792 Then strFileAs = .CompanyAndFullName '"Company (Last, First)"
                If myValue = 32793 Then strFileAs = .FullNameAndCompany '"Last, First (Company)"
                If myValue = 32823 And .CompanyName <> "" And .FullName = "" Then strFileAs = .CompanyName '"Company"
                If myValue = 32823 And .FullName <> "" Then strFileAs = .FullName '"First Last"

0
0
Reply
Robert L
March 11, 2018 12:35 pm

Your code is absolute GOLD! I had to remember how to get to the macros and create a new module tho ...haha. But it ran to perfection!.

One minor suggestion. I have about 10 contacts that are Company name only. When I chose First Name Last Name, The 10 contacts did not stay as FileAs CompanyName. They got cleared out. I'll probably modify the code but thought you might want to change it.

0
0
Reply

Visit Slipstick Forums.
What's New at Slipstick.com

Latest EMO: Vol. 30 Issue 29

Subscribe to Exchange Messaging Outlook






Support Services

Do you need help setting up Outlook, moving your email to a new computer, migrating or configuring Office 365, or just need some one-on-one assistance?

Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • Week Month All
  • Jetpack plugin with Stats module needs to be enabled.
  • Move Deleted Items to Another Folder Automatically
  • Open Outlook Templates using PowerShell
  • Count and List Folders in Classic Outlook
  • Google Workspace and Outlook with POP Mail
  • Import EML Files into New Outlook
  • Opening PST files in New Outlook
  • New Outlook: Show To, CC, BCC in Replies
  • Insert Word Document into Email using VBA
  • Delete Empty Folders using PowerShell
  • Warn Before Deleting a Contact
Ajax spinner

Recent Bugs List

Microsoft keeps a running list of issues affecting recently released updates at Fixes or workarounds for recent issues in classic Outlook (Windows).

For new Outlook for Windows: Fixes or workarounds for recent issues in new Outlook for Windows .

Outlook for Mac Recent issues: Fixes or workarounds for recent issues in Outlook for Mac

Outlook.com Recent issues: Fixes or workarounds for recent issues on Outlook.com

Office Update History

Update history for supported Office versions is at Update history for Office

Outlook Suggestions and Feedback

Outlook Feedback covers Outlook as an email client, including Outlook Android, iOS, Mac, and Windows clients, as well as the browser extension (PWA) and Outlook on the web.

Outlook (new) Feedback. Use this for feedback and suggestions for Outlook (new).

Use Outlook.com Feedback for suggestions or feedback about Outlook.com accounts.

Other Microsoft 365 applications and services




New Outlook Articles

Move Deleted Items to Another Folder Automatically

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Google Workspace and Outlook with POP Mail

Import EML Files into New Outlook

Opening PST files in New Outlook

New Outlook: Show To, CC, BCC in Replies

Insert Word Document into Email using VBA

Delete Empty Folders using PowerShell

Warn Before Deleting a Contact

Newest Code Samples

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Insert Word Document into Email using VBA

Warn Before Deleting a Contact

Use PowerShell to Delete Attachments

Remove RE:, FWD:, and Other Prefixes from Subject Line

Change the Mailing Address Using PowerShell

Categorize @Mentioned Messages

Send an Email When You Open Outlook

Delete Old Calendar Events using VBA

VBA Basics

How to use the VBA Editor

Work with open item or selected item

Working with All Items in a Folder or Selected Items

VBA and non-default Outlook Folders

Backup and save your Outlook VBA macros

Get text using Left, Right, Mid, Len, InStr

Using Arrays in Outlook macros

Use RegEx to extract message text

Paste clipboard contents

Windows Folder Picker

Custom Forms

Designing Microsoft Outlook Forms

Set a custom form as default

Developer Resources

Developer Resources

Developer Tools

VBOffice.net samples

SlovakTech.com

Outlook MVP David Lee

Repair PST

Convert an OST to PST

Repair damaged PST file

Repair large PST File

Remove password from PST

Merge Two Data Files

Sync & Share Outlook Data

  • Share Calendar & Contacts
  • Synchronize two computers
  • Sync Calendar and Contacts Using Outlook.com
  • Sync Outlook & Android Devices
  • Sync Google Calendar with Outlook
  • Access Folders in Other Users Mailboxes

Diane Poremsky [Outlook MVP]

Make a donation

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

Productivity

Productivity Tools

Automatic Message Processing Tools

Special Function Automatic Processing Tools

Housekeeping and Message Management

Task Tools

Project and Business Management Tools

Choosing the Folder to Save a Sent Message In

Run Rules on messages after reading

Help & Suggestions

Submit Outlook Feature Requests

Slipstick Support Services

Buy Microsoft 365 Office Software and Services

Visit Slipstick Forums.

What's New at Slipstick.com

Home | Outlook User | Exchange Administrator | Office 365 | Outlook.com | Outlook Developer
Outlook for Mac | Common Problems | Utilities & Addins | Tutorials
Outlook & iCloud Issues | Outlook Apps
EMO Archives | About Slipstick | Slipstick Forums
Submit New or Updated Outlook and Exchange Server Utilities

Send comments using our Feedback page
Copyright © 2025 Slipstick Systems. All rights reserved.
Slipstick Systems is not affiliated with Microsoft Corporation.

:wpds_smile::wpds_grin::wpds_wink::wpds_mrgreen::wpds_neutral::wpds_twisted::wpds_arrow::wpds_shock::wpds_unamused::wpds_cool::wpds_evil::wpds_oops::wpds_razz::wpds_roll::wpds_cry::wpds_eek::wpds_lol::wpds_mad::wpds_sad::wpds_exclamation::wpds_question::wpds_idea::wpds_hmm::wpds_beg::wpds_whew::wpds_chuckle::wpds_silly::wpds_envy::wpds_shutmouth:
wpDiscuz

Sign up for Exchange Messaging Outlook

Our weekly Outlook & Exchange newsletter (bi-weekly during the summer)






Please note: If you subscribed to Exchange Messaging Outlook before August 2019, please re-subscribe.

Never see this message again.

You are going to send email to

Move Comment