Link to home
Start Free TrialLog in
Avatar of rrhandle8
rrhandle8Flag for United States of America

asked on

Using VBA to fill a web form not working

I have spent two days on this.  Time to ask for help.  I am placing orders on Overstock.  The following code gives different errors when I try to select from two drop-down boxes.
I item is live, so you can try it on your end.



Enum READYSTATE
    READYSTATE_UNINITIALIZED = 0
    READYSTATE_LOADING = 1
    READYSTATE_LOADED = 2
    READYSTATE_INTERACTIVE = 3
    READYSTATE_COMPLETE = 4
End Enum

Sub Connect()
'to refer to the running copy of Internet Explorer
Dim ie As InternetExplorer
'to refer to the HTML document returned
Dim html As HTMLDocument
'open Internet Explorer in memory, and go to website
Set ie = New InternetExplorer
ie.Visible = True
ie.navigate "http://www.overstock.com/Bedding-Bath/Aloha-Girls-Multicolor-Printed-Cotton-Pieced-Quilt-Set/5036546/product.html?keywords=12915080&searchtype=Header"
'Wait until IE is done loading page
Do While ie.READYSTATE <> READYSTATE_COMPLETE
DoEvents
Loop

varTemp = Split("12915080-6882393", "-")
ItemNum = varTemp(0)
OptionNum = varTemp(1)
ProductNum = "5036546"
ElementID = "addid" & ProductNum
ie.document.getElementById(ElementID).Value = OptionNum

ElementID = "addqty" & ProductNum
ie.document.getElementById(ElementID).Value = 4

Stop
        ie.navigate "http://www.yahoo.com"
        Do While ie.Busy: DoEvents: Loop
        Do Until ie.READYSTATE = READYSTATE_COMPLETE: DoEvents: Loop

ie.Quit
Set ie = Nothing


End Sub

Open in new window

Avatar of Glenn Ray
Glenn Ray
Flag of United States of America image

I tweaked the code and got no errors, but also no real results aside from the Overstock and Yahoo windows opening:
Sub Connect()
    'to refer to the running copy of Internet Explorer
    Dim ie As Object
    
    'to refer to the HTML document returned
    Dim html As Object
    
    'open Internet Explorer in memory, and go to website
    Set ie = CreateObject("InternetExplorer.Application")
    ie.Visible = True
    ie.navigate "http://www.overstock.com/Bedding-Bath/Aloha-Girls-Multicolor-Printed-Cotton-Pieced-Quilt-Set/5036546/product.html?keywords=12915080&searchtype=Header"
    
    'Wait until IE is done loading page
    Do While ie.READYSTATE <> READYSTATE_COMPLETE
        DoEvents
    Loop
    
    varTemp = Split("12915080-6882393", "-")
    ItemNum = varTemp(0)
    OptionNum = varTemp(1)
    ProductNum = "5036546"
    ElementID = "addid" & ProductNum
    ie.document.getElementById(ElementID).Value = OptionNum
    
    ElementID = "addqty" & ProductNum
    ie.document.getElementById(ElementID).Value = 4
    Stop
    
    ie.navigate "http://www.yahoo.com"
    Do While ie.Busy: DoEvents: Loop
    Do Until ie.READYSTATE = READYSTATE_COMPLETE: DoEvents: Loop

    ie.Quit
    Set ie = Nothing
End Sub

Open in new window


-Glenn
Avatar of rrhandle8

ASKER

Glenn,
I tried your code.  It has the same problem I had before: The qty does not get set.  Put a stop right before the yahoo link.
There must be another method that will allow the quantity field to update.  If one manually selects the same option ("Twin"), the quantity field updates dynamically. In the code, it does not.  However, I'm at a loss as to what method you can use to make this happen.
Me too, Glenn.  This is a tough one.
ASKER CERTIFIED SOLUTION
Avatar of James Elliott
James Elliott
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial