Hi everyone,
I found a nice macro which allows me to extract an email from a weblink as below.
Function GetEmail(URL As String)
Dim IE As Object, WebText As String
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate URL
While IE.ReadyState <> 4
DoEvents
Wend
WebText = IE.Document.body.innerHTML
IE.Quit
Set IE = Nothing
GetEmail = GetEmailAddress(WebText)
End Function
Function GetEmailAddress(ByVal S As String) As String
Dim X As Long, AtSign As Long
Dim Locale As String, Domain As String
Locale = "[A-Za-z0-9.!#$%&'*/=?^_`{|}~+-]"
Domain = "[A-Za-z0-9._-]"
AtSign = InStr(S, "@")
If AtSign = 0 Then Exit Function
For X = AtSign To 1 Step -1
If Not Mid(" " & S, X, 1) Like Locale Then
S = Mid(S, X)
If Left(S, 1) = "." Then S = Mid(S, 2)
Exit For
End If
Next
AtSign = InStr(S, "@")
For X = AtSign + 1 To Len(S) + 1
If Not Mid(S & " ", X, 1) Like Domain Then
S = Left(S, X - 1)
If Right(S, 1) = "." Then S = Left(S, Len(S) - 1)
GetEmailAddress = S
Exit For
End If
Next
End Function
This macro is quite nice but it is not powerful enought. For example, it just finds anything starting with @. I just wants to search the following keywords for email addresses - if they are found then show it in that cell. If there are more than one keywords found, then the enhanced macro will put additional emails along the line. Please help me improve this code so that: it pulls out all email addresses containing the keywords below.
admin
contact
enquiry
hello
info
mail
office
Bookmarks