Get data from website screen to Excel with form - VBA

后端 未结 2 545
不知归路
不知归路 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 00:57

    Sorry misunderstand the question Initially.

    Now i got what OP wants.

    Here I'm not going to tell how to click the open button in the download window.

    But result will export the required data into excel(that's what OP want it seems)

    Tested and working fine in my system.

    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
       ' ie.document.getelementbyid("ctl00_ContentPlaceHolder1_btnDownload").Click
    
    Set doc = ie.document
    
    For Each d In doc.all.tags("table")
    
    If InStr(d.innertext, "Client Name") > 0 Then
    
    With d
            For x = 0 To .Rows.Length - 1
                For y = 0 To .Rows(x).Cells.Length - 1
                    Sheets(1).Cells(x + 1, y + 1).Value = .Rows(x).Cells(y).innertext
                Next y
            Next x
        End With
    
    End If
    
    Next d
        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
    

提交回复
热议问题