'----------------------------------------------------------------------------------
' This function will return valid or invalid
'-----------------------------------------------------------------------------------
Public Function checkdisplayname(name_email) 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(name_email)
oRecip.Resolve
If oRecip.Resolved Then
checkdisplayname = "Valid"
Else
checkdisplayname = "Invalid"
End If
End Function
'----------------------------------------------------------------------------------
' This function will return email address if valid, else blank value will be returned
'-----------------------------------------------------------------------------------
Public Function checkdisplayname_email(name_email) 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(name_email)
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
checkdisplayname_email = oEU.PrimarySmtpAddress
End If
Case 10, 30 'olOutlookContactAddressEntry & 'olSmtpAddressEntry
checkdisplayname_email = oRecip.AddressEntry.Address
End Select
End If
End Function
Sub checknames()
email_or_name = "support"
MsgBox checkdisplayname(email_or_name)
MsgBox checkdisplayname_email(email_or_name)
End Sub
VBA Outlook KPI Excel Alt+F11 Dashboards Macros Recording Graphs Automation Developer WaterFall Powerpoint Charts Pivot Tables Forecast Charts