2016-08-19 43 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

當然,我已經添加了完整的代碼(我知道這非常麻煩,這是因爲我試圖修復它有多少次迭代)。謝謝! –

相關問題