Sharid
Well-known Member
- Joined
- Apr 22, 2007
- Messages
- 1,066
- Office Version
- 2016
- Platform
- Windows
Hi
Can some please help me update this code it was originally written by Rick Rothstein, the original post is HERE (but this post is messed up, the code is at the bottom of the thread.)
I am trying to get the code to work for multiple URL. The Urls List will be in Sheet1 Column A Starting from Row2 Down. I would like the results to go into Sheet1 column B next to the url. If nothing is found then either leave that cell blank or place a hyphen in it.
Thanks
Can some please help me update this code it was originally written by Rick Rothstein, the original post is HERE (but this post is messed up, the code is at the bottom of the thread.)
I am trying to get the code to work for multiple URL. The Urls List will be in Sheet1 Column A Starting from Row2 Down. I would like the results to go into Sheet1 column B next to the url. If nothing is found then either leave that cell blank or place a hyphen in it.
VBA Code:
Sub GetEmail()
Dim IE As Object, WebText As String, Email As String
Const URL As String = "[URL]http://www.weissinc.com/contact[/URL]"
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate URL
While IE.ReadyState <> 4
DoEvents
Wend
WebText = IE.Document.body.innerhtml
IE.Quit
Set IE = Nothing
Email = GetEmailAddress(WebText)
'
' The Email variable contains the email address
' so do whatever you want with it here.
'
End Sub
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
Thanks