< Public Function JustAddressNoAlias (EmailAddress As String) As String (?)

Comments

'------------------------------------------------------------------ 'Returns the a@b part of an address, and not the part '------------------------------------------------------------------

Public Function JustAddressNoAlias (EmailAddress As String) As String

    Dim Pos1 As Integer
    Dim Pos2 As Integer
    
    'Look for the 2 delimiters
    Pos1 = InStr(EmailAddress, "<")
    Pos2 = InStr(EmailAddress, ">")
    
    'If can't find delimiters, just use the whole lot
    If Pos1 < 1 Or Pos2 < Pos1 Then
        
        JustAddressNoAlias = EmailAddress
        
    Else
    
        'Otherwise delete the alias
        JustAddressNoAlias = Mid(EmailAddress, Pos1 + 1, Pos2 - Pos1 - 1)
                
    End If
    
    'Remove comma-separated value, if necessary
    If InStr(EmailAddress, ",") > 0 Then
        JustAddressNoAlias = Left(JustAddressNoAlias, InStr(EmailAddress, ",") - 1)
    End If

    'Trim whitespace off ends
    JustAddressNoAlias = Trim(JustAddressNoAlias)
End Function


Copying, Return to index