0

I am getting an error of "object variable or with block variable not set" when this macro runs. The highlighted line to debug is the 2nd one from the bottom - "estimate.Click". When I hover the mouse over "Set estimate" on the next line up, it says "estimate=Nothing". "estimate.submit" acts the same way. The corresponding button on the webpage is never clicked. All the rest of this code is working well.

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
Set estimate = ieApp.document.getElementById("btnRequestEstimates")
estimate.Click
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

End Sub
  • Please stay to one question: it's not polite to ignore those who are trying to help you. If someone (me in this case) makes a suggestion in a comment to one of your questions, try it out, then respond with another comment *in that question*, or update your question to reflect the change you tried. It makes it much easier for anyone else coming along later to follow the progression to the final answer. – Tim Williams Jan 11 '12 at 21:00
  • http://stackoverflow.com/questions/8816557/vba-access-remote-website-automate-clicking-submit-after-already-automating-cli – Tim Williams Jan 11 '12 at 21:49

1 Answers1

1

I'm not sure if this completely relates, but I had similar issues with JS errors using VBA automation. What I found to be successful was to make sure each and every JS function that would have been called by performing this action manually is still triggered using the code.

For example, given this button:

<BUTTON id=btnExample onfocus="return focusFunction(this);" onclick="return clickFunction(this);" name=btnExample>

VBA to call:

    Set objButton = IE.Document.getElementByID("btnExample")
    objButton.onfocus
    objButton.onclick

There may also be other functions on the page or attached to other elements that need to be called as well (which may include some sort of page unload function), so you'll have to look into the code of that window to tell for sure.

After I discovered this, following these steps has always been successful for me.

Gaffi
  • 4,307
  • 8
  • 43
  • 73