VBA access to a remote website, automatic button click after automation button click on another web page

I work with vba in excel 2010 and Internet Explorer 8 and Vista. The code below works to go to the remote website and publish the form. On the final page, the code should click the "Get Grades" button. Instead, I get this error "object variable or with non-blocking variable". The highlighted problematic line in the code is "evaluation = ieApp.document.getElementById (" btnRequestEstimates ")".

I think part of the problem might be that a button that doesn't work is a submit button that is not part of the form. I am also wondering if the variables should be reset before pressing the second button. The error message implies that this is a qualification problem, but I consider this a fairly standard way of qualifying an element in this situation. These are some of the things I searched on Google, but I'm not sure what the problem is.

Sub btn_version() Dim ieApp As Object Dim ieDoc As Object Dim ieForm As Object Dim ieObj As Object Dim URL As String Dim estimate As Object 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 While ieApp.Busy Or ieApp.readyState <> 4: DoEvents: Wend Set ieDoc = ieApp.document Set ieForm = ieDoc.forms(1) For Each ieObj In ieForm.Elements If ieObj.ClassName = "AddToCartButton" Then ieObj.Click End If Next ieObj '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' While ieApp.Busy Or ieApp.readyState <> 4: DoEvents: Wend estimate = ieApp.document.getElementById("btnRequestEstimates") estimate.submit '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' End Sub 
+1
source share
1 answer

The code below combines your xmlhttp code from automating the sending of a message form, which is located on the website with vba and xmlhttp (to better control POST , that is, skip the Set ieDoc = ieApp.document in our question) by clicking the "btnRequestEstimates on the last Url from on this page

 Sub Scrape2() Dim objIE As Object Dim xmlhttp As Object Dim ieButton As Object Dim strResponse As String Dim strUrl As String strUrl = "http://www.craft-e-corner.com/addtocart.aspx?returnurl=showproduct.aspx%3fProductID%3d2688%26SEName%3dnew-testament-cricut-cartridge" Set objIE = CreateObject("InternetExplorer.Application") objIE.navigate "about:blank" Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP") '~~> Indicates that page that will receive the request and the type of request being submitted xmlhttp.Open "POST", "http://www.craft-e-corner.com/addtocart.aspx?returnurl=showproduct.aspx%3fProductID%3d2688%26SEName%3dnew-testament-cricut-cartridge", False '~~> Indicate that the body of the request contains form data xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" '~~> Send the data as name/value pairs xmlhttp.Send "Quantity=1&VariantID=2705&ProductID=2688" strResponse = xmlhttp.responseText objIE.navigate strUrl objIE.Visible = True Do While objIE.readystate <> 4 DoEvents Loop objIE.document.Write strResponse Set xmlhttp = Nothing Set ieButton = objIE.document.getelementbyid("btnRequestEstimates") ieButton.Click End Sub 
+3
source

All Articles