错误91“对象变量或未设置块变量”

时间:2019-12-02 00:19:22

标签: excel vba

Sub Test()

Dim ie As InternetExplorer
Dim ht As HTMLDocument
Dim i As Integer

i = 1

Set ie = New InternetExplorer

ie.Visible = True

'Boston Celtics
ie.navigate ("https://www.espn.com/nba/team/stats/_/name/bos/boston-celtics")

Application.Wait Now + TimeValue("00:00:05")

For Each ht In ie.document.getElementsByClassName("Table_TH")(0).getElementsByTagName("tr")
    With ActiveSheet
    .Range("A" & i).Value = ht.Children(0).textContent
    .Range("B" & i).Value = ht.Children(1).textContent
    .Range("C" & i).Value = ht.Children(2).textContent
    .Range("D" & i).Value = ht.Children(3).textContent
    .Range("E" & i).Value = ht.Children(4).textContent
    .Range("F" & i).Value = ht.Children(5).textContent
    .Range("G" & i).Value = ht.Children(6).textContent
    .Range("H" & i).Value = ht.Children(7).textContent
    .Range("I" & i).Value = ht.Children(8).textContent
    .Range("J" & i).Value = ht.Children(9).textContent
    .Range("K" & i).Value = ht.Children(10).textContent
    .Range("L" & i).Value = ht.Children(11).textContent
    .Range("M" & i).Value = ht.Children(12).textContent
    .Range("N" & i).Value = ht.Children(13).textContent
    .Range("O" & i).Value = ht.Children(14).textContent
    End With
    i = i + 1
Next ht

我在For Each循环中收到错误。

0 个答案:

没有答案