excel macro/vb http get results in excel

folks

via Excel (cell a1 ) I access a url, how in cell a2 can I view the http response code?

all help will do, would like to build this in a macro

cheers
rutgermonsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

FaustulusCommented:
Please try this code,
Private Sub TestGetStatus()
    GetStatus "A1"
End Sub

Sub GetStatus(ByVal Ref As String)

    Dim HttpReq As Object
    Dim Rslt As Variant
    
    Set HttpReq = CreateObject("MSXML2.XMLHTTP")
    
    On Error Resume Next
    With HttpReq
        .Open "GET", ActiveSheet.Range(Ref).Value, False
        .Send
        If Err Then
            Rslt = "No connection"
        Else
            Rslt = Val(.Status)
            If Err Then
                Rslt = "No Response"
            Else
                Rslt = "Status: " & Rslt
            End If
        End If
    End With
    ActiveSheet.Range(Ref).Offset(0, 1).Value = Rslt
End Sub

Open in new window

Enter your URL in column A. See the response in column B.
For testing, please use the procedure 'TestGetStatus'. Amend the referenced cell in column A as required.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rutgermonsAuthor Commented:
how can I get this to look at all rows in colum a?
0
FaustulusCommented:
This should do the job:-
Private Sub WriteStatus()

    Dim R As Long
    
    For R = 1 To Cells(Rows.Count, 1).End(xlUp).Row
            GetStatus Cells(R, 1).Address
    Next R
End Sub

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.