Check if URL exists, is so then return true

Hi everyone, I'm hoping someone can help with this function. it will check if a URL exists. If it does, would like it to return true and if it does not, then false.

Function Test_URLExists()
  Dim url As String
  
  url = "http://www.puresourcecode.com/"
  MsgBox url, vbInformation, URLExists(url)
  
  url = "http://www.puresourcecode.com/showthread.apx?t=1"
  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

Happy coding!

Advertsing

125X125_06





MonthList

CommentList