excel check if url exists code example

Example: excel check if url exists

Function Test_URLExists()
  Dim url As String
  
  url = "http://www.mrexcel.com/forum/showthread.php?t=567315"
  MsgBox url, vbInformation, URLExists(url)
  
  url = "http://xwww.mrexcel.com/forum/showthread.php?t=567315"
  MsgBox url, vbInformation, URLExists(url)
End Function

Function URLExists(url As String) As Boolean
    Dim Request As Object
    Dim ff As Integer
    Dim rc As Variant
    
    On Error GoTo EndNow
    Set Request = CreateObject("WinHttp.WinHttpRequest.5.1")
    
    With Request
      .Open "GET", url, False
      .Send
      rc = .StatusText
    End With
    Set Request = Nothing
    If rc = "OK" Then URLExists = True
    
    Exit Function
EndNow:
End Function

Tags:

Misc Example