excel vba check if certain website is online

Valentin

Board Regular
Joined
Oct 29, 2010
Messages
77
I have a code (function) to determine if an Internet connection exists, but I would also like to know the code if a particular website is online.
 

sergioMabres

Well-known Member
Joined
Feb 24, 2013
Messages
946
Hi Valentin,
You could have a cell with the URL i.e. http://www.somesite.com
Use a function to get the HTML from URL
Code:
Function getHtmlFromUrl(pURL As String) As String
     Dim resText As String
     Dim objHttp As Object
     Set objHttp = CreateObject("MSXML2.ServerXMLHTTP")
     objHttp.Open "GET", pURL, False
     objHttp.Send ""
     getHtmlFromUrl = Mid(objHttp.ResponseText, 1, 255) 
End Function
Is the function getHtmlFromUrl returns an error then site is offline
If you get a string starting with &lt!doctype html&gt &lthtml...<html<html..." site="" is="" online
cheers
Sergio</html<html...">
 
Last edited:

FFischer

Board Regular
Joined
Oct 10, 2013
Messages
59
Hi Valentin,
You could have a cell with the URL i.e. http://www.somesite.com
Use a function to get the HTML from URL
Code:
Function getHtmlFromUrl(pURL As String) As String
     Dim resText As String
     Dim objHttp As Object
     Set objHttp = CreateObject("MSXML2.ServerXMLHTTP")
     objHttp.Open "GET", pURL, False
     objHttp.Send ""
     getHtmlFromUrl = Mid(objHttp.ResponseText, 1, 255) 
End Function
Is the function getHtmlFromUrl returns an error then site is offline
If you get a string starting with &lt!doctype html&gt &lthtml...<HTML<HTML..." online
cheers
Sergio</HTML<HTML...">
Sergio

I shoud find this useful. Can you explain where exactly do you place the URL in question? Thanks!

Frank
 

sergioMabres

Well-known Member
Joined
Feb 24, 2013
Messages
946
Hi Frank
I do not know how much you know about VBA so if it looks dumb I mean no disrespect
Code:
' Function declares a user defined function that you can use from a cell like
' if you write =getHtmlFromUrl("http://www.yoursite.com/samepage.html") in B2
' or you write =getHtmlFromUrl(A3) in B3 and A3 has ="http://www.yoursite.com/samepage.html"
' here pURL is the parameter where the URL string is stored
Function getHtmlFromUrl(pURL As String) As String
     ' Creates a variable resText I think I am not using this      
     Dim resText As String
     ' Creates a variable objHttp to store a very small internet browser       
     Dim objHttp As Object
     ' Creates the browser and stores it in the variable      
     Set objHttp = CreateObject("MSXML2.ServerXMLHTTP")
     ' Uses the browser to navigate to the page        
     objHttp.Open "GET", pURL, False      
     objHttp.Send ""      
     ' fetches the page into the variable getHtmlFromUrl that is what the cell gets 
     getHtmlFromUrl = Mid(objHttp.ResponseText, 1, 255)  
End Function
I hope it helps
Cheers
 

Forum statistics

Threads
1,078,134
Messages
5,338,432
Members
399,233
Latest member
mmgezer

Some videos you may like

This Week's Hot Topics

Top