excel vba check if certain website is online

Valentin

Board Regular
Joined
Oct 29, 2010
Messages
96
Office Version
  1. 365
Platform
  1. Windows
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.
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
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:
Upvote 0
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,213,561
Messages
6,114,312
Members
448,564
Latest member
ED38

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top