Need to pull data from website after every 5 seconds using Vba

Posted by Milton on Super User See other posts from Super User or by Milton
Published on 2014-06-06T08:24:10Z Indexed on 2014/06/06 9:29 UTC
Read the original article Hit count: 181

Filed under:
|
|

I need to pull data from www.dsebd.org after ever 5 seconds. this Vba code pull data but does not run automatically. Please help me.

Sub ButtonCode()

     ' execute macros
    Call GetCotton
     ' submit macro to run again in 5 sec
    Application.OnTime Now + TimeValue("00:00:05"), "ButtonCode"

End Sub

Sub GetCotton()

        Dim xml    As Object
    Dim html   As Object
    Dim elemcollection As Object
    Dim result As String
    Dim t As Long, r As Long, c As Long, ActRw As Long
    Set xml = CreateObject("MSXML2.XMLHTTP.6.0")
    With xml
        .Open "GET", "http://www.dsebd.org/dseX_share.php", False
        .send
    End With
    result = xml.responseText
    Set html = CreateObject("htmlfile")
    html.body.innerHTML = result
    Set elemcollection = html.getElementsByTagName("table")
    For t = 0 To elemcollection.Length - 1
        For r = 0 To elemcollection(t).Rows.Length - 1
            For c = 0 To elemcollection(t).Rows(r).Cells.Length - 1
                ThisWorkbook.Sheets("Sheet1").Cells(ActRw + r + 1, c + 1) = elemcollection(t).Rows(r).Cells(c).innerText
            Next c
        Next r
        ActRw = ActRw + elemcollection(t).Rows.Length + 1
    Next t
End Sub

© Super User or respective owner

Related posts about windows-7

Related posts about Windows