The following code was posted by Justin Dearing here: url checker VBA, when redirected, show redirected url
However, how on earth can I call this function to return T/F AND the target? I've tried various ways (Call, straight request etc) and continue to get compile errors, invalid use of object.
If I cut the function down to: Public Function GetResult(strUrl As String) As Boolean
This returns the T/F for a 301 or 302 however doesn't return the target.
What is the correct approach to calling this function to get the isRedirect True/False AND the target redirected too? What am I missing?
Any pointers appreciated. B
Public Function GetResult(ByVal strUrl As String, Optional ByRef isRedirect As Boolean, Optional ByRef target As String) As String
Dim oHttp As New WinHttp.WinHttpRequest
oHttp.Option(WinHttpRequestOption_EnableRedirects) = False
oHttp.Open "HEAD", strUrl, False
oHttp.send
GetResult = oHttp.Status & " " & oHttp.statusText
If oHttp.Status = 301 Or oHttp.Status = 302 Then
isRedirect = True
target = oHttp.getResponseHeader("Location")
Else
isRedirect = False
target = Nothing
End If
End Function