Get data from website screen to Excel with form - VBA

后端 未结 2 544
不知归路
不知归路 2020-12-22 00:17

With help from Stackoverflow, I reached to the following code; it basically opens IE, navigate to the url, fills the form and submit.

Sub getdata()
    Appli         


        
2条回答
  •  抹茶落季
    2020-12-22 01:01

    Try this

    Sub getdata()
        Application.ScreenUpdating = False
    
        Set IE = CreateObject("InternetExplorer.Application")
        IE.Visible = True
        IE.Navigate "http://www.bseindia.com/markets/equity/EQReports/BulknBlockDeals.aspx?expandable=7"
    
        Application.StatusBar = "Submitting"
        ' Wait while IE loading...
        While IE.Busy
            DoEvents
        Wend
        ' **********************************************************************
        delay 5
        IE.document.getelementbyid("ctl00_ContentPlaceHolder1_chkAllMarket").Click
        delay 5
        IE.document.getelementbyid("ctl00_ContentPlaceHolder1_txtDate").Value = "01/01/2014"
        delay 5
        IE.document.getelementbyid("ctl00_ContentPlaceHolder1_txtToDate").Value = "12/01/2014"
        delay 5
        IE.document.getelementbyid("ctl00_ContentPlaceHolder1_btnSubmit").Click
        delay 5
    
        '**********************************************************************
        Application.StatusBar = "Form Submitted"
    
        Dim tbl As Object, tr As Object, trCol As Object, td As Object, tdCol As Object
        Dim row As Long
        Dim col As Long
    
        row = 1
        col = 1
    
        Set tbl = IE.document.getelementbyid("ctl00_ContentPlaceHolder1_divData1").getElementsbytagname("Table")(0)
        Set trCol = tbl.getElementsbytagname("TR")
    
        For Each tr In trCol
            Set tdCol = tr.getElementsbytagname("TD")
            For Each td In tdCol
                Cells(row, col) = td.innertext
                col = col + 1
            Next
            col = 1
            row = row + 1
        Next
    
    
        IE.Quit            'will uncomment line once working
        Set IE = Nothing   'will uncomment line once working
    
        Application.ScreenUpdating = True
    End Sub
    
    Private Sub delay(seconds As Long)
        Dim endTime As Date
        endTime = DateAdd("s", seconds, Now())
        Do While Now() < endTime
            DoEvents
        Loop
    End Sub
    

提交回复
热议问题