I found this code on the internet. It checks that URL's are still valid. Saves me clicking each one of my favourites to see they are still valid.
these are the return codes (status) I'm getting but how are they generated
200 - ok
301 - moved permanently
302 - found
403 - forbidden
what is the difference between 200 and 302 .
what does 301 moved permanently mean
what does 403 - forbidden mean
i'm really looking for ok or not found as my results. ok if web page found, not found if web page not found
glassescase
Code:
Public PageSource As String
Public httpRequest As Object
Dim HL As Hyperlink
Sub ValidateURLs()
Dim Cell As String 'Range
Dim Rng As Range
Dim RngEnd As Range
Dim Status As String
Dim Wks As Worksheet
' Set Wks = ActiveSheet
' Set Rng = Wks.Range("A2")
Range("B2").Select
start:
' Set RngEnd = Wks.Cells(Rows.Count, Rng.Column).End(xlUp)
' If RngEnd.Row < Rng.Row Then Exit Sub Else Set Rng = Wks.Range(Rng, RngEnd)
' For Each Cell In Rng
If ActiveCell.Address = ("$B$1189") Then
MsgBox ("url's checked exiting")
Exit Sub
End If
Cell = ActiveCell.Text
If ActiveCell.Value = "" Or ActiveCell.Value = Empty Then
ActiveCell.Offset(1, 0).Select 'down 1 across 0
'MsgBox ("No url in cell, exiting")
' Exit Sub
GoTo start
End If
Status = GetURLStatus(Cell)
If Status <> "200 - OK" Then
ActiveCell.Offset(0, 1).Select 'across 1
'Cell = Status
ActiveCell.Value = Status
ActiveCell.Offset(0, -1).Select 'back 1
Else
ActiveCell.Offset(0, 1).Select 'across 1
'Cell = Status
ActiveCell.Value = Status
ActiveCell.Offset(0, -1).Select 'back 1
End If
' Next Cell
ActiveCell.Offset(1, 0).Select
GoTo start
End Sub
Function GetURLStatus(ByVal URL As String, Optional AllowRedirects As Boolean)
Const WinHttpRequestOption_EnableRedirects = 6
If httpRequest Is Nothing Then
On Error Resume Next
Set httpRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
If httpRequest Is Nothing Then
Set httpRequest = CreateObject("WinHttp.WinHttpRequest.5")
End If
Err.Clear
On Error GoTo 0
End If
' Control if the URL being queried is allowed to redirect.
httpRequest.Option(WinHttpRequestOption_EnableRedirects) = AllowRedirects
' Clear any pervious web page source information
PageSource = ""
' Add protocol if missing
If InStr(1, URL, "://") = 0 Then
URL = "http://" & URL
End If
' Launch the HTTP httpRequest synchronously
On Error Resume Next
httpRequest.Open "GET", URL, False
If Err.Number <> 0 Then
' Handle connection errors
GetURLStatus = Err.Description
Err.Clear
Exit Function
End If
On Error GoTo 0
' Send the http httpRequest for server status
On Error Resume Next
httpRequest.Send
httpRequest.WaitForResponse
If Err.Number <> 0 Then
' Handle server errors
PageSource = "Error"
GetURLStatus = Err.Description
Err.Clear
Else
' Show HTTP response info
GetURLStatus = httpRequest.Status & " - " & httpRequest.StatusText
' Save the web page text
PageSource = httpRequest.ResponseText
End If
On Error GoTo 0
End Function
these are the return codes (status) I'm getting but how are they generated
200 - ok
301 - moved permanently
302 - found
403 - forbidden
what is the difference between 200 and 302 .
what does 301 moved permanently mean
what does 403 - forbidden mean
i'm really looking for ok or not found as my results. ok if web page found, not found if web page not found
glassescase