Extract text from field

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I'm trying to get the email domain name from an email address. So the text
between the @ sign and the first '.' after the @ sign. I'm aware this is not
100% correct as some mail addresses have more '.' behind the @ sign, any clue
how to make it better is welcome as well?
 
Use Instr() to locate the @ and the dot in the string, and Mid() to parse
it.

This kind of thing:

Public Function GetDomain(varEmail As Variant) As Variant
'Purpose: Parse the domain from an email address.
'Assumes: Domain is between @ and first dot after that.
Dim lngPosAt As Long
Dim lngPosDot As Long
Dim strEmail As String

GetDomain = Null

If varEmail <> vbNullString Then
lngPosAt = InStr(varEmail, "@")
If lngPosAt > 0 Then
lngPosDot = InStr(varEmail, ".")
End If
If lngPosDot > 0 Then
GetDomain = Mid(varEmail, lngPosAt + 1, lngPosDot - lngPosAt -
1)
End If
End If
End Function
 
Thanks for this Allen,

It works for email addresses with only 1 dot, but seems to be a problem when
there's more dots like '(e-mail address removed)'

Mark
 
Sorry, Mark. Can't believe I left out the starting point when searching for
the dot, after we already got it in the variable:

lngPosDot = InStr(lngPosAt, varEmail, ".")
 
Back
Top