2016-08-19 117 views
1

尝试修改刮宏以单击网页上的按钮。我在下面的代码中收到错误91,并且不能为我的生活找出原因。它不喜欢的对象是“dd”对象。我已经尝试了迄今为止在这里看到的所有内容,所以任何新颖的想法都将非常感谢!VBA宏“对象变量或未设置块变量”无法找出原因

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 
+0

尝试从'Set dd'或Dim dd'设置'Set'作为'Ob​​ject'。 – Bathsheba

+0

感谢您的提示,我已经尝试了两种修复方法。我也尝试调暗为一个字符串。 –

+0

该行末尾的“Click”看起来很奇怪。看起来像一个不返回值的函数。 – Bathsheba

回答

0

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

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

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

我建议如下做。请调试并查看返回任意值的右侧方程

+0

感谢Siva和MacroMarc,我尝试了你的两个修复程序,但仍然得到相同的错误。我甚至不知道在这一点上怎么可能得到这个错误... –

+0

@HenryK,是否可以发布你的整个代码,以便我可以尝试找出最新错误并尝试修复 – Siva

+0

当然,我已经添加了完整的代码(我知道这非常麻烦,这是因为我试图修复它有多少次迭代)。谢谢! –

相关问题