Showing posts with label Validate Link. Show all posts
Showing posts with label Validate Link. Show all posts

Friday, March 2, 2012

Validate URL using Excel Macro

Here is the that you can use whether the set of URLs are valid or not valid:

Sub Validate_URLs()
Dim r As Range
Dim URLs As String
For Each r In ActiveSheet.Range("A2:A5146")
URLs = Trim(r.Value)
If Len(URLs) > 0 Then
r.Offset(0, 1).Value = IIf(HttpExists(URLs), "Valid", "Not Valid")
End If
Next r
End Sub
Function HttpExists(sURL As String) As Boolean
Dim oXHTTP As Object
Set oXHTTP = CreateObject("MSXML2.XMLHTTP")
oXHTTP.Open "HEAD", sURL, False
oXHTTP.send
HttpExists = (oXHTTP.Status = 200)
End Function