The default email display name in the address book used to be "Full Name (Email1)", "Full Name (Email2)", "Full Name (Email3)" but was changed to "Full Name (email address)". If you upgraded from an earlier version of Outlook, your contacts may use a mix of display name formats. The code below will allow you to easily convert all contacts to a uniform format or remove the address for security reasons, per a discussion in TechNet forums:
Using the File As... format without (email address) displayed, when people forward emails, messages will not contain the email address visible for others, just the display name, or not accessible for worms or other user's mailbox attackers.
This code sample works on the Display name for the default email address (Email1) but can easily be changed to work with Email2 or Email3.
This code sample was created from Change Contact's File As format
To change the File as format on existing contacts, see Bulk Change File As Format for Contacts. Our third "Bulk change Contacts" VBA sample is at Bulk Move Phone Numbers to a Different Phone Field.
The Name column (1) is controlled by the Address book setting. Column 2, the email Display Name, defaults to Full Name (email address) format. The code on this page will change this field.
To change the Name column (1) in Outlook 2010 and newer, you'll start at File, Account Settings, Address book Tab, double click on the Outlook Address book. In Outlook 2007, the options for the Name column format is at Tools, Account Settings, Address book Tab, double click on the Outlook Address book and choose between Full name or File as format.
Note that when you edit a contact's email address, the display name is rewritten using Outlook's default format. You'll need to edit it before saving the contact.
While you can't change the default settings for the Display Name field (it always uses 'Full name (address)' format), you can use VBA to change your contacts so they all use the same format. Your choices are limited to Full name, Last First, FileAs, and Company. You can include the email address by adding this code to the format code: & " (" & .Email1Address & ")".
Default email display name format:
After running the VBA code below:
When you click the To button, the entry in the Address book will now look like this:
Not up to working with VBA code? See Tools for tools that can make this change.
Two formats in the code sample below are less than useful as Display name formats:
strFileAs = .CompanyName & " " & .FullName & " (" & .Email1Address & ")"
Results in a leading space if the Contact does not have a Company listed.
'strFileAs = .FileAs
Uses only the Company name in the display name when the FileAs format is "Company name (Fullname)".
Note: I updated the code below to check for email addresses. If an address does not exist, the contact is skipped.
VBA Code to Change the Email Display Name
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.
This code was tested with Outlook 2010, 2007, and 2003. (May trigger the Email security prompts in Outlook 2003.)
If you have multiple contacts folders, ChangeEmailDisplayName_SelectedContacts will change the selected contacts. It checks for an email address (If .Email1Address <> "" Then) and only updates contacts with email addresses.
Public Sub ChangeEmailDisplayName() 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 If .Email1Address <>"" Then ' Uncomment the strFileAs line for the desired format ' Add the email address to any string using ' the following code: ' & " (" & .Email1Address & ")" 'Firstname Lastname (email address) format ' strFileAs = .FullName & " (" & .Email1Address & ")" 'Lastname, Firstname format strFileAs = .LastNameAndFirstName 'Company name (email address) format ' strFileAs = .CompanyName & " (" & .Email1Address & ")" 'Comapany Firstname Lastname (email address) format 'the display name will have a leading space if 'the contact doesn't have a company name 'strFileAs = .CompanyName & " " & .FullName & " (" & .Email1Address & ")" 'File As format 'Does not support Company (Fullname) format. 'Only Company name is used in the display name 'strFileAs = .FileAs .Email1DisplayName= strFileAs .Save End If 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
How to use the Macro
First: You will need macro security set to low during testing.
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, it’s at Tools, Macro Security. If Outlook tells you it needs to be restarted, close and reopen Outlook. Note: after you test the macro and see that it works, you can either leave macro security set to low or sign the macro.
Now open the VBA Editor by pressing Alt+F11 on your keyboard.
To put the code in a module:
- Right click on Project1 and choose Insert > Module
- Copy and paste the macro into the new module.
- Click the Run button in the VBA editor to run it, or if you need to run this frequently, add a button for the macro toyour ribbon.
More information as well as screenshots are at How to use the VBA Editor.
More Information
More Bulk Change Contact articles at Slipstick.com:
- Bulk Change Contact's FileAs Format to Match Outlook's Default Setting
- 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
Diane,
Came across your script and it works beautifully. I do have a question hopefully, you might be able to help me out or point me to the right source.
We recently migrated from Google Workspace to MS 365 with Exchange online. All of my contacts migrated fine however, opening a contact, the contact's email address is in email3 instead email1. Is there a script/tool that I can run/use to copy email addresses from email3 to email1?
Thanks.
Jimmy
Thanks so much for this, this worked perfectly.
If I want to have the "Display As" to be "FirstName and Last Name" rather than "Lastname and firstname" how do I go about doing that?
You'd use :
strFileAs= .firstname & " " & .lastname
or
strFileAs = .fullname
Your original code worked perfectly; however, I've got a number of contacts with no company listed. I tried embedding a second if statement so I don't get empty "()" at the end of some contacts, but I get a Compile Error: End With without With. Modified code is below. What am I missing?
With objContact
If .Email1Address <> "" Then
If .CompanyName <> "" Then
'Firstname Lastname (Company) format
strFileAs = .FullName & " " & "(" & .CompanyName & ")"
.Email1DisplayName = strFileAs
.Save
ElseIf .Email1Address <> "" Then
If .CompanyName = "" Then
'Firstname Lastname format
strFileAs = .FullName
.Email1DisplayName = strFileAs
.Save
End If
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
it looks like it's missing an if -
End If
end if
End With
End If
(the last end if is not needed if there is not an IF line before the With line. )
Thanks for the quick reply. Unfortunately, I'm still getting the same error message. I tried changing the closing argument to:
End If
End If
End With
End If
When that did not work, I tried:
End If
End If
End With
I received the same error message every time.
I got it to work with these lines.
.Save
End If
End If
End If
End With
Err.Clear
End If
Next
Thanks!
One final question, does this code only work on contacts stored in an Outlook/microsoft account? I have my icloud email and contacts set up in Outlook 2010. The code work fine to change names for all my work contacts in my Exchange account, but when I run the macro on my iCloud contacts, it doesn't change anything.
Thank you so much!!!! This saved me (and, in turn, my grandparents) so much time! It's also given me a chance to take a look at visual basic macros, thanks again for broadening my horizon!
Hi all,
I've just run this code and it's worked exactly as I think it should have in that all my contacts Display As fields are now "last name, first name".
The reason I'm unsure if this is the outcome that is expected is that this is my first time ever running a macro or using VBA. For that reason also I'm not sure how to change the code to get what I would like, and wouldn't even be confident enough to understand the required changes even if someone has already posted it here (apologies if that's the case and I'm going over old ground).
What I would like to do is change all my contacts Display As fields to "Full Name - Company (email)". How should I change the code (currently exactly a is above) to achieve this?
Any help would be very much appreciated.
if you want fullname - company (email) and its not a default format, you need to the fields together:
strFileAs = .fullname & " - " & .companyname & "(" & .email1address & ")"
you can test it without change anything first by replacing this line:
.Email1DisplayName= strFileAs
with
debug.print strfileas
Then View menu > Immediate window before running the macro.
You'll see the results in the VBA editor.
Diane - I recently imported my contacts into a new Outlook 365 account and the sorting and view are different. The card used to show Last Name, First Name followed by Company Name (in the grey area) and then in the card Display As, the Full Name (email address). I tried running a few of your fixes but obviously don't know what I am doing. Please help!
Sorry I missed this earlier. Did you get it straightened out? You need to open one contact then click the Full Name button to see if they are in the right fields. If so, the problem is the view - I'd try resetting it or customizing it.
outlook 2016 will not send emails using outlook.com with email address in "display as". how do I remove them?
use the macro on this page and either
strFileAs = .LastNameAndFirstName
or
strFileAs = .Fullname
but... my guess is the problem is something else as Outlook's default is to create the display name in name (address) format.
Is your account on the new server?
Hello Diane,
I tried running the code, but it does not seem to work. It is my first time using VBA and I am not getting any errors when I run it. I think I might be doing something wrong. I currently am running Outlook 2016 with Office. My user has over 1000 contacts and I am unable to get the First Name Last Name to show with the email address in autocomplete when typing in email. There are also times when some addresses do not come up at all when I start typing. By the way, I do have Cached Exchange Mode checked in case you were wondering.
Do you have macro security set to low?