I am new to using VBA and Macros and am wondering if there is a way to add a "check names" function in Excel (similar to the function in Outlook). Part of the form I am working on requires me to enter names of employees and I would like to be able to click a button to make sure I have spelled their names correctly and they are in our email system. Any help or pointers in the right direction would be greatly appreciated!
Asked
Active
Viewed 1.4k times
1
-
Depending on how many names, you could use a list (hidden in your personal workbook?) in Excel and flag if not on that list using a For loop and an IF, or if there aren't many, you could write a CASE statement in VBA. Then you flag if they aren't on the 'approved' list – Trum Jul 01 '15 at 12:50
-
could you not design a outlook form querying data from centrally stored Excel? that way you have all outlook mail functions and I believe this is much more realistic as querying outlook names require access grant on outlook (?) – Krishna Jul 01 '15 at 12:54
-
Where do you need to check names? In the Outlook Address Book or AD? – Eugene Astafiev Jul 01 '15 at 13:17
1 Answers
5
A couple of answers here:
Edit: Created in Excel 2010 (no idea if it'll work in 2003).
The first will return TRUE or FALSE if the name can be resolved in Outlook.
'----------------------------------------------------------------------------------
' Procedure : ResolveDisplayNameToSMTP
' Author : Sue Mosher - updated by D.Bartrup-Cook to work in Excel late binding.
'-----------------------------------------------------------------------------------
Public Function ResolveDisplayName(sFromName) As Boolean
Dim OLApp As Object 'Outlook.Application
Dim oRecip As Object 'Outlook.Recipient
Dim oEU As Object 'Outlook.ExchangeUser
Dim oEDL As Object 'Outlook.ExchangeDistributionList
Set OLApp = CreateObject("Outlook.Application")
Set oRecip = OLApp.Session.CreateRecipient(sFromName)
oRecip.Resolve
If oRecip.Resolved Then
ResolveDisplayName = True
Else
ResolveDisplayName = False
End If
End Function
The second will resolve the name and return the email address:
'----------------------------------------------------------------------------------
' Procedure : ResolveDisplayNameToSMTP
' Author : Sue Mosher - updated by D.Bartrup-Cook to work in Excel late binding.
'-----------------------------------------------------------------------------------
Public Function ResolveDisplayNameToSMTP(sFromName) As String
Dim OLApp As Object 'Outlook.Application
Dim oRecip As Object 'Outlook.Recipient
Dim oEU As Object 'Outlook.ExchangeUser
Dim oEDL As Object 'Outlook.ExchangeDistributionList
Set OLApp = CreateObject("Outlook.Application")
Set oRecip = OLApp.Session.CreateRecipient(sFromName)
oRecip.Resolve
If oRecip.Resolved Then
Select Case oRecip.AddressEntry.AddressEntryUserType
Case 0, 5 'olExchangeUserAddressEntry & olExchangeRemoteUserAddressEntry
Set oEU = oRecip.AddressEntry.GetExchangeUser
If Not (oEU Is Nothing) Then
ResolveDisplayNameToSMTP = oEU.PrimarySmtpAddress
End If
Case 10, 30 'olOutlookContactAddressEntry & 'olSmtpAddressEntry
ResolveDisplayNameToSMTP = oRecip.AddressEntry.Address
End Select
End If
End Function
Here's a test procedure showing how to use both functions:
Sub Test()
MsgBox ResolveDisplayName("Marty Moesta")
MsgBox ResolveDisplayNameToSMTP("Marty Moesta")
End Sub

Darren Bartrup-Cook
- 18,362
- 1
- 23
- 45
-
1Keep in mind that Namespace.CreateRecipient / Recipient.Resolve will not display ambiguous name dialog box. – Dmitry Streblechenko Jul 01 '15 at 15:13
-
I'd never even considered that @Dmitry - I'm going to have to work on that. Found this link which may point me in the right direction - https://msdn.microsoft.com/en-us/library/bb646055(v=office.12).aspx – Darren Bartrup-Cook Jul 01 '15 at 15:27
-
Yes, that is for selecting the names, not for ambiguous names. – Dmitry Streblechenko Jul 01 '15 at 15:29