我正在尝试从报告工具中获取缺陷和状态。
我得到的第一件事:
运行时错误:91对象变量或未设置块变量
然后,如果我调试它,我收到以下错误:
运行时错误1004:应用程序定义或对象定义错误
代码如下:
Sheet2.Rows(i, 1).Value = DefectNo
以下是完整代码:
Option Explicit
Sub Defects_Click()
Dim IE As New InternetExplorer
IE.Visible = True
IE.navigate "Reporting tool URL"
Do
DoEvents
Loop Until IE.readyState = READYSTATE_COMPLETE
Dim doc As HTMLDocument
Set doc = IE.document
Dim status As Variant
Dim i As Integer
Dim DefectNo As Variant
For i = 1 To 100
DefectNo = doc.getElementsByClassName("cn_formattedid0")(i).innerText
status = doc.getElementsByClassName("cn_state0")(i).innerText
Sheet2.Activate
Sheet2.Rows(i, 1).Value = DefectNo
Sheet2.Rows(i, 2).Value = status
Next i
IE.Quit
Set doc = Nothing
End Sub
答案 0 :(得分:0)
尝试更改此内容,
Sheet2.Rows(i, 1).Value = DefectNo
Sheet2.Rows(i, 2).Value = status
到此,
Sheet2.Cells(i, 1).Value = DefectNo
Sheet2.Cells(i, 2).Value = status