problems programmatically working with forms on websites

excel-yes

New Member
Joined
May 10, 2011
Messages
9
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
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
I tried the code below instead. This doesn't work either. It says there is an error with document. When the .visible line isn't commented out, 2 windows open instead of 1. The form I am trying to submit is the 2nd form on the webpage.


Sub Click_a_btn_without_name_or_id_with_class_with_dynamic_form_name()

Dim ieApp As Object
Dim ieDoc As Object
Dim URL As String
URL = "http://www.craft-e-corner.com/p-2688-new-testament-cricut-cartridge.aspx"
Set ieApp = CreateObject("InternetExplorer.Application")
'ieApp.Visible = True
ieApp.Navigate URL
Set ieDoc = ieApp.document
ieDoc.Forms(1).Item("AddToCartButton").Click

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,262
Members
452,627
Latest member
KitkatToby

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top