Hello Jose77,
It isn't clear to me what you want when you say "content". Your first post centers around the IP address of the host. Then in your second post you say...
So, let me re-state my question: how can I retrieve a website from Excel VBA and get the content?
I am guessing you want the IP address for a given URL. This macro will do that. There is one annoyance. The Command screen is visible while it is running. It closes when the macro finishes, but it does work.
'Written: Septemeber 27, 2009
'Author: Leith Ross
'Summary: Returns the IP address for a given URL.
Function GetIPAddress(URL As String) As String
Dim Exec As Object
Dim IP As String
Dim RegExp As Object
Dim S As String
Dim WSH As Object
Set RegExp = CreateObject("VBscript.RegExp")
RegExp.Global = True
RegExp.MultiLine = True
Set WSH = CreateObject("WScript.Shell")
Set Exec = WSH.Exec("ping.exe www.thecodecage.com")
S = Exec.StdOut.ReadAll()
RegExp.Pattern = "\[.+\]"
If RegExp.Test(S) Then
IP = RegExp.Execute(S)(0)
RegExp.Pattern = "(\[|\])"
IP = RegExp.Replace(IP, "")
End If
GetIPAddress = IP
Set WSH = Nothing
Set Exec = Nothing
Set RegExp = Nothing
End Function
Example
Sub TestIt()
Dim URL As String
URL = "www.excelforum.com"
MsgBox "The IP Address for " & URL & " is:" & vbCrLf & GetIPAddress(URL)
End Sub
Bookmarks