title: How to check the status of URL?
body: <p>I created a macro, in which I can fetch each URL from any webpage.</p>
  
  <p>Now, I have each URL in column.</p>
  
  <p>How can I check if a URL is working.</p>
  
  <p>If any one of these URL is not working then it should show me error not working next to URL in next column.</p>
  
  <p>Below is the code I wrote:</p>
  
  <pre><code>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 &lt;&gt; 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") &lt;&gt; "" Then Debug.Print htmlElement.getAttribute("href")
      If htmlElement.getAttribute("href") &lt;&gt; "" 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
  </code></pre>
  
  <p>This code is to fetch the URL from web-page.</p>
  
  <p>Below is the code to check the status of URL, if it is working or not.</p>
  
  <pre><code>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 &lt;&gt; 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
  </code></pre>