Test To See if A Web URL Exists
If you need to test to see if a Web URL exists from Excel, the procedure below will accomplish your objective. You first must include the library shown below when in the Visual Basic Environment by selecting Tools, Then References:
Program Code
Private Sub TestForURLExists() ' *************************************************************** ' From Your Main Code, Include The Following To Call The URL ' Tester ' *************************************************************** Dim strURLToTest As String strURLToTest = "http://www.logicwurks.com" If Not TestIfURLExists(strURLToTest) Then MsgBox ("URL " & strURLToTest & " Does Not Exist") End If End Sub Private Function TestIfURLExists(strURL As String) As Boolean ' **************************************************************** ' Test for URL Existence ' **************************************************************** ' You Must Include The Following From The Visual Basic Editor ' Select Tools, References, then include: ' Microsoft WinHTTP Services Version (latest version) ' **************************************************************** Dim oURL As New WinHttpRequest On Error GoTo TestURL_Err With oURL .Open "GET", strURL, False .Send TestIfURLExists = (.Status = 200) End With TestURL_Err: ' **************************************************************** ' On An Error, It Will Return a Zero (False) ' **************************************************************** Set oURL = Nothing End Function