Skip to content

Instantly share code, notes, and snippets.

@ndthanh
Created July 11, 2017 10:13
Show Gist options
  • Save ndthanh/36ab044d3bd996563bc5c090277f4fc9 to your computer and use it in GitHub Desktop.
Save ndthanh/36ab044d3bd996563bc5c090277f4fc9 to your computer and use it in GitHub Desktop.
Function ExtractEmailFun(extractStr As String) As String
'Update 20130829
Dim CharList As String
On Error Resume Next
CheckStr = "[A-Za-z0-9._-]"
OutStr = ""
Index = 1
Do While True
Index1 = VBA.InStr(Index, extractStr, "@")
getStr = ""
If Index1 > 0 Then
For p = Index1 - 1 To 1 Step -1
If Mid(extractStr, p, 1) Like CheckStr Then
getStr = Mid(extractStr, p, 1) & getStr
Else
Exit For
End If
Next
getStr = getStr & "@"
For p = Index1 + 1 To Len(extractStr)
If Mid(extractStr, p, 1) Like CheckStr Then
getStr = getStr & Mid(extractStr, p, 1)
Else
Exit For
End If
Next
Index = Index1 + 1
If OutStr = "" Then
OutStr = getStr
Else
OutStr = OutStr & Chr(10) & getStr
End If
Else
Exit Do
End If
Loop
ExtractEmailFun = OutStr
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment