VBA - 从多个Internet Explorer选项卡获取数据

时间:2017-01-30 09:06:10

标签: excel vba excel-vba

我想从www.moodys.com和www.fitchratings.com等网站获得信用评级。

起初我的代码工作正常,它从fitchratings.com获取我想要的数据然后它将URL更改为www.moodys.com并从那里获取数据,一切都很好。但是当我想用CLng(2048)打开网站www.moodys.com的新标签时,我得到一个运行时错误'91'。

如何解决此错误?

这是我的代码:

    Private Sub AkbankNotGün_Click()
    Dim IE As New InternetExplorer
    IE.Visible = True
    'For Fitch
    IE.navigate "https://www.fitchratings.com/gws/en/esp/issr/80089736"

    Do         
        DoEvents
    Loop Until IE.readyState = READYSTATE_COMPLETE

    Dim doc As HTMLDocument
    Set doc = IE.document
    Dim unot As String
    Dim knot As String
    Dim tarih As String
    Dim tkd As String

    tarih = doc.getElementsByClassName("rating_noborders")(1).innerText
    Range("B4").Value = tarih
    unot = doc.getElementsByClassName("rating")(0).innerText
    knot = doc.getElementsByClassName("rating")(1).innerText
    Range("D4").Value = unot & "/" & knot
    tkd = doc.getElementsByClassName("rating")(5).innerText
    Range("D5").Value = tkd


    'For Moody's
    IE.navigate "https://www.moodys.com/credit-ratings/Akbank-TAS-credit-rating-600017220", CLng(2048)

    Do         
        DoEvents
    Loop Until IE.readyState = READYSTATE_COMPLETE

    tarih = doc.getElementsByClassName("dateValue")(0).innerText
    Range("F4").Value = tarih
    unot = doc.getElementsByClassName("link rating_link")(0).innerText
    Range("H4").Value = unot
    tkd = doc.getElementsByClassName("link rating_link")(12).innerText
    Range("H5").Value = tkd
End Sub

提前致谢,

0 个答案:

没有答案