VBA宏“对象变量或未设置块变量”无法弄清楚原因

时间:2016-08-19 14:31:06

标签: excel vba excel-vba

尝试修改抓取宏以单击网页上的按钮。我在下面的代码中收到错误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

2 个答案:

答案 0 :(得分:0)

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

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

pygtk

答案 1 :(得分:0)

我建议如下。请调试并查看右侧方程式是否返回任何值

{{1}}