VBAmacros“对象variables或与块variables未设置”无法找出原因

试图修改一个刮macros来点击网页上的一个button。 我在下面的代码中得到错误91,并且不能为我的生活找出原因。 它不喜欢的对象是“dd”对象。 我已经尝试了迄今为止在这里看到的所有内容,所以任何新鲜的想法都将非常感激!

Application.Calculation = xlCalculationManual Application.ScreenUpdating = False Application.EnableEvents = True Dim wb1 As Workbook Dim ws1 As Worksheet Dim MyURL As String Dim Rows As Long, links As Variant, IE As InternetExplorer, link As Variant Dim i As Long Dim sID As String Dim rngLinks As Range, rngLink As Range Dim filterRange As Range Dim copyRange As Range Set wb1 = ThisWorkbook Set ws1 = wb1.Worksheets("Sheet1") Set IE = New InternetExplorer Rows = ws1.Cells(ws1.Rows.Count, "A").End(xlUp).Row Set rngLinks = ws1.Range("E2:E" & Rows) i = 2 With IE .Visible = True .navigate ("https://www.samplesite.com/account/update") While .Busy Or .readyState <> 4: DoEvents: Wend Application.Wait (Now() + TimeValue("00:00:006")) Dim doc As Object Set doc = IE.document Dim classNameElem As Variant Dim tagNameElem As Variant Set classNameElem = doc.getElementsByClassName("thisisaclass")(0) If (classNameElem <> Null) Then Set tagNameElem = classNameElem.getElementsByTagName("input")(0) End If If (tagNameElem <> Null) Then tagNameElem.Click End If End With Application.Calculation = xlCalculationAutomatic Application.ScreenUpdating = True Application.EnableEvents = True ws1.Activate Set rngLinks = Nothing End Sub 

1)不要将点击的结果设置为任何variables

2)将方法的名称更改为getElementsByTagName:

 doc.getElementsByClassName("thisclassname")(0).getElementsByTagName("thistagname")(0).Click 

我会build议做如下。 请debugging,看看右侧方程返回任何值

 Dim classNameElem As Variant Dim tagNameElem As Variant Set classNameElem = doc.getElementsByClassName("thisclassname")(0) If (Not classNameElem Is Nothing) Then Set tagNameElem = classNameElem.getElementsByTagName("input")(0) End If If (Not classNameElem Is Nothing) Then tagNameElem.Click End If End If