Created
July 11, 2017 10:13
-
-
Save ndthanh/36ab044d3bd996563bc5c090277f4fc9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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