How to check the status of URL?

check url status online
check http status code in javascript
http request header check
test urls
http status codes
url redirect checker
status checker
url itor

I created a macro, in which I can fetch each URL from any webpage.

Now, I have each URL in column.

How can I check if a URL is working.

If any one of these URL is not working then it should show me error not working next to URL in next column.

Below is the code I wrote:

Sub CommandButton1_Click()
Dim ie As Object
Dim html As Object
Dim j As Integer
j = 1
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
url = "www.mini.co.uk"
ie.navigate url

Do While ie.READYSTATE <> READYSTATE_COMPLETE
    Application.StatusBar = "Trying to go to website ..."
Loop

Application.StatusBar = " "
Set html = ie.document
'Dim htmltext As Collection
Dim htmlElements As Object
Dim htmlElement As Object
Set htmlElements = html.getElementsByTagName("*")

For Each htmlElement In htmlElements
    'If htmlElement.getAttribute("href") <> "" Then Debug.Print htmlElement.getAttribute("href")
    If htmlElement.getAttribute("href") <> "" Then Cells(j, 1).Value = htmlElement.getAttribute("href")
    j = j + 1
Next

ActiveSheet.Range("$A$1:$A$2752").removeDuplicates Columns:=1, Header:=xlNo

End Sub

This code is to fetch the URL from web-page.

Below is the code to check the status of URL, if it is working or not.

Sub CommandButton2_Click()
Dim k As Integer
Dim j As Integer
k = 1
j = 1
'Dim Value As Object
'Dim urls As Object
'urls.Value = Cells(j, 1)

For Each url In Cells(j, 1)
    Dim ie As Object
    Set ie = CreateObject("InternetExplorer.Application")
    ie.Visible = False
    url = Cells(j, 1)
    ie.navigate url

    Do While ie.READYSTATE <> READYSTATE_COMPLETE
        Application.StatusBar = "checking the Data. Please wait..."
    Loop

    Cells(k, 2).Value = "OK"
    'Set html = ie.document
    ie.Quit
    j = j + 1
    k = k + 1
Next

End Sub

Since you are interested to know whether the link is working, xmlhttp may be one solution.

Set sh = ThisWorkBook.Sheets("Sheet1")
Dim column_number: column_number = 2

'Row starts from 2
For i=2 To 100
    strURL = sh.cells(i,column_number)
    sh.cells(i, column_number+1) = CallHTTPRequest(strURL)
Next


Function CallHTTPRequest(strURL)
    Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")
    objXMLHTTP.Open "GET", strURL, False
    objXMLHTTP.send
    status = objXMLHTTP.Status
    'strContent = ""

    'If objXMLHTTP.Status = 200 Then
    '   strContent = objXMLHTTP.responseText
    'Else
    '   MsgBox "HTTP Request unsuccessfull!", vbCritical, "HTTP REQUEST"
    '   Exit Function
    'End If
    Set objXMLHTTP = Nothing
    CallHTTPRequest = status
End Function

3 Free Tools to Check HTTP Response Status, Free bulk and single URL server header response code checker and meta refresh detection script. See also: Spider Test Tool · W3C HTTP Status Codes  Choose the site with the page you need to check from the list. Go to the Indexing → Check URL Status section. Enter the page URL and click Check. Note. In the field, you can enter the full URL or the relative path from the site root beginning with “/”.

Public Function IsURLGood(url As String) As Boolean
    Dim request As New WinHttpRequest

    On Error GoTo IsURLGoodError
    request.Open "HEAD", url
    request.Send
    If request.Status = 200 Then
        IsURLGood = True
    Else
        IsURLGood = False
    End If
    Exit Function

IsURLGoodError:
    IsURLGood = False
End Function

Sub testLink()

Dim source As Range, req As Object, url$



  Set source = Range("A2:B2")


  source.Columns(2).Clear


  For i = 1 To source.Rows.Count

  url = source.Cells(i, 1)
    If IsURLGood(url) Then
    source.Cells(i, 2) = "OK"
    Else
    source.Cells(i, 2) = "Down"
    End If

Next

  MsgBox "Done"

End Sub

HTTP Status Codes Checker ~ Server Header Response Code , Open URLs in external services (for example, Serpstat, Ahrefs, Google PageSpeed); Try other reports. Checking status codes in Netpeak Spider  When you arrive on the page, you want to enter the URL to the page you want to test. Then click submit for a basic check. For a more advanced check, Web Sniffer lets you configure a few extra settings, including changing the user-agent from Web-Sniffer to different browsers or to Googlebot.

You can actually get the status codes using IE automation, but it requires working with events and a reference to the Microsoft Internet Controls library.

Private Declare PtrSafe Sub SleepEx Lib "Kernel32.dll" (ByVal dwMilliseconds As Long, Optional ByVal bAlertable As Boolean = True)
Private WithEvents ie As SHDocVw.InternetExplorer
Private LastStatusCode As Long

Private Sub ie_NavigateError(ByVal pDisp As Object, URL As Variant, TargetFrameName As Variant, StatusCode As Variant, Cancel As Boolean)
    LastStatusCode = StatusCode
End Sub

Public Sub NavigateReturnStatus(url As String) As Long
    Set ie = CreateObject("InternetExplorer.Application")
    Status = 0
    ie.Navigate url
    Do While IEObject.ReadyState <> READYSTATE_COMPLETE Or IEObject.Busy
         SleepEx 50 'No busy waiting, short wait time
         DoEvents 'Need to receive events from IE application
    Loop
    NavigateReturnStatus = LastStatusCode
End Sub

This doesn't return a conventional HTTP status code, but instead returns a NavigateError status code. That means you can get more detailed information about errors, but no information about successful navigation. Of course, if it's 0, no error has occurred so the status is likely 200.

Speed is very much slower than a WinHTTP/MSXML approach, but I'm sharing this mainly for cases where someone's already navigating using Internet Explorer anyway.

Of course, the code can (and likely should) be modified to reuse the internet explorer application.

How to Check HTTP Status Code: Server Response Codes in , A good URL should always return status code 200. A good SEO redirect should always return 301 (beware of 302 redirects - see below). You can also use this tool  Quick command to check the status of a URL (Linux, BSD, OS X) July 28, 2009 General bsd , linux , os x , tips Daz There may be times when you just want to do a quick check to see whether a web site is up, and/or what status message the web server is showing.

Sub URLWorkingorNot()

'Make Sure to Select Cells containing URL

Dim i As Long

AddReference i= 1

    Selection.Replace "#N/A", "NA": Selection.Offset(0, 1).EntireColumn.Insert
    Dim IE As InternetExplorer
        If ActiveWorkbook Is Nothing Then Exit Sub
        For Each cell In Selection
        If cell.Value <> "" Then
            Set IE = New InternetExplorer
                IE.Navigate2 cell.Value
                IE.Left = 900
                IE.Width = 900
                IE.Visible = True
                While IE.Busy: DoEvents: Wend
                On Error Resume Next
                If InStr(1, IE.document.body.innerText, "The webpage cannot be found", vbBinaryCompare) <> 0 Then cell.Offset(0, 1).Value = "Not Available"
                'MsgBox IE.document.body.innerText
                If err.Number <> 0 Then err.Clear: On Error GoTo 0
                IE.Quit: Set IE = Nothing
        End If
            i = i + 1:
            ProgressBar Selection.Count, i, "Working on " & i & " Cell": DoEvents
        If ActiveWorkbook.Path <> "" And Left(i, 3) = "00" Then ActiveWorkbook.Save
        Next cell
        Unload UProgressBar
Application.StatusBar = ""
End Sub

Sub AddReference() 'cOPIED FROM iNTERNET

     'Macro purpose:  To add a reference to the project using the GUID for the
     'reference library

    Dim strGUID As String, theRef As Variant, i As Long

     'Update the GUID you need below.
    'strGUID = "{00020905-0000-0000-C000-000000000046}"
     strGUID = "{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}"
     'iNTERNET cONTROLS - "{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}" MAJOR 1 MINOR 1
     'HTMLOBJECT "{3050F1C5-98B5-11CF-BB82-00AA00BDCE0B}" MAJOR 4 MINOR 0

     'Set to continue in case of error
    On Error Resume Next

     'Remove any missing references
    For i = ThisWorkbook.Vbproject.References.Count To 1 Step -1
        Set theRef = ThisWorkbook.Vbproject.References.Item(i)
        If theRef.isbroken = True Then
            ThisWorkbook.Vbproject.References.Remove theRef
        End If
    Next i

     'Clear any errors so that error trapping for GUID additions can be evaluated
    err.Clear

     'Add the reference
    ThisWorkbook.Vbproject.References.AddFromGuid _
    GUID:=strGUID, Major:=1, Minor:=0
    ThisWorkbook.Vbproject.References.AddFromFile "C:\Windows\System32\UIAutomationCore.dll"
     'If an error was encountered, inform the user
    Select Case err.Number
    Case Is = 32813
         'Reference already in use.  No action necessary
    Case Is = vbNullString
         'Reference added without issue
    Case Else
         'An unknown error was encountered, so alert the user
        MsgBox "A problem was encountered trying to" & vbNewLine _
        & "add or remove a reference in this file" & vbNewLine & "Please check the " _
        & "references in your VBA project!", vbCritical + vbOKOnly, "Error!"
    End Select
    On Error GoTo 0
End Sub

Check the HTTP Status Code of the website header, Check HTTP Status Codes, redirect locations and number of chained redirects final redirect locations/status codes and response times for URLs in Bulk (it can  Check status code and redirection of your website based on user-agent. Link Explorer Explore links in the URL provided and create a tree view of the same.

URLitor: Bulk HTTP Status & Redirect Checker, Check your URL redirect for accuracy. add http:// or https:// on your URL. redirects; · check and show redirect chains; · check http headers like Status Code,​  Windows 10 lets you quickly check your network connection status. And if you're having trouble with your connection, you can run the Network troubleshooter to try and fix it. Select the Start button, then select Settings > Network & Internet > Status. Check your network connection status

Redirect Checker, Choose ping tab on Host Tracker to check your site status. Fill in the information required — your website URL and the test location. Choose All  Powershell Script for Website Availability Monitoring / URL Monitoring Powershell script for website availability monitoring/URL Monitoring. This Script will take the list of URLs from a text tile( in this case from D:\URLList.txt)as input, and results output with URL, StatusCode, Description, Response Length and time taken fields in a HTML Report.

How to Check if a Website is Down or Working Worldwide, There may be times when you just want to do a quick check to see whether a web site is up, and/or what status message the web server is  View case status online using your receipt number, which can be found on notices that you may have received from USCIS. Also, sign up for Case Status Online to: . Receive automatic case status updates by email or text message, . View your case history and upcoming case activities, .

Comments
  • Try around something in these links msdn.microsoft.com/en-us/library/ms767625(v=vs.85).aspx and msdn.microsoft.com/en-us/library/windows/desktop/…
  • To check the status of a link you only only need to make a HEAD request: there's no need to fetch the full contents.
  • Hi Barney, Thank you fort this code, I think I need to remove the comments from code, then it works fine.
  • As above but with "HEAD" in place of "GET"
  • @TimWilliams Both method works fine, however, it just prints status 200 but if my website have some error it doent print any msg.
  • How did I miss this? Nice +