When I run the macro below I get this error - Method 'Busy' of object 'IWebbrowser2' failed. In debug this line is highlighted - While ieApp.Busy Or ieApp.ReadyState <> 4: DoEvents: Wend
Also I think I have set the variables wrong for pid and vid. They are hidden elements in the same form as the button I am trying to click.
Can someone please tell me how to fix those 2 problems, and also WHY they are wrong? I have been trying to figure this out for a long time and no amount of googling is helping.
Sub Click_a_btn_without_name_or_id_with_class_and_in_form_with_dynamic_name()
Dim ieApp As Object
Dim ieDoc As Object
Dim ieForm As Object
Dim ieObj As Object
Dim URL As String
Dim pid As Object
Dim vid As Object
URL = "http://www.craft-e-corner.com/p-2688-new-testament-cricut-cartridge.aspx"
Set ieApp = CreateObject("InternetExplorer.Application")
ieApp.Navigate URL
While ieApp.Busy Or ieApp.ReadyState <> 4: DoEvents: Wend
Set ieDoc = ieApp.Document
Set pid = ieDoc("ProductID")
Set vid = ieDoc("VariantID")
Set ieForm = ieDoc.Forms("AddToCartForm_" & pid & "_" & vid)
For Each ieObj In ieForm.Elements
If ieObj.ClassName = "AddToCartButton" Then
ieObj.Click
End If
Next ieObj
End Sub
Also I think I have set the variables wrong for pid and vid. They are hidden elements in the same form as the button I am trying to click.
Can someone please tell me how to fix those 2 problems, and also WHY they are wrong? I have been trying to figure this out for a long time and no amount of googling is helping.
Sub Click_a_btn_without_name_or_id_with_class_and_in_form_with_dynamic_name()
Dim ieApp As Object
Dim ieDoc As Object
Dim ieForm As Object
Dim ieObj As Object
Dim URL As String
Dim pid As Object
Dim vid As Object
URL = "http://www.craft-e-corner.com/p-2688-new-testament-cricut-cartridge.aspx"
Set ieApp = CreateObject("InternetExplorer.Application")
ieApp.Navigate URL
While ieApp.Busy Or ieApp.ReadyState <> 4: DoEvents: Wend
Set ieDoc = ieApp.Document
Set pid = ieDoc("ProductID")
Set vid = ieDoc("VariantID")
Set ieForm = ieDoc.Forms("AddToCartForm_" & pid & "_" & vid)
For Each ieObj In ieForm.Elements
If ieObj.ClassName = "AddToCartButton" Then
ieObj.Click
End If
Next ieObj
End Sub