Pulling Upside/downside Capture Ratio from morningstar.com

前端 未结 1 1842
故里飘歌
故里飘歌 2021-01-21 10:51

First Time Long Time.

New to this VBA thing, however catching on.

I\'m interested in pulling the upside/downside capture ratio for a lot of mutual funds and want

1条回答
  •  攒了一身酷
    2021-01-21 11:24

    Try below code.

    Sub Test()
    
        Dim IE As Object, Doc As Object, lastRow As Long, tblTR As Object, tblTD As Object, strCode As String
        lastRow = Range("A65000").End(xlUp).Row
    
    
        Set IE = CreateObject("internetexplorer.application")
        IE.Visible = True
    
    
        For i = 1 To lastRow
    
            strCode = "FDSAX"    ' Range("A" & i).value  ' kindly change it as per your requirement. Currently hardcoded
    
            IE.navigate "http://performance.morningstar.com/fund/ratings-risk.action?t=" & "FDSAX"
    
            Do While IE.readystate <> 4: DoEvents: Loop
    
            Set Doc = CreateObject("htmlfile")
            Set Doc = IE.document
    
    tryAgain:
            Set tblTR = Doc.getelementbyid("div_upDownsidecapture").getelementsbytagname("tr")(3)
    
            If tblTR Is Nothing Then GoTo tryAgain
    
            j = 2
            For Each tblTD In tblTR.getelementsbytagname("td")
                tdVal = Split(tblTD.innerText, vbCrLf)
                Cells(i, j) = tdVal(0)
                Cells(i, j + 1) = tdVal(1)
                j = j + 2
            Next
    
    
        Next
    End Sub
    

    0 讨论(0)
提交回复
热议问题