vba - READYSTATE never get the COMPLETED state -
the below macro works in ie9, when using ie11 stops on do while
statement. also, set htmldoc = ie.document
not work same reason.
note website not work restricted users only.
option explicit sub gethtmldocument() dim ie new shdocvw.internetexplorer dim htmldoc mshtml.htmldocument dim htmlinput mshtml.ihtmlelement dim htmlbuttons mshtml.ihtmlelementcollection dim htmlbutton mshtml.ihtmlelement ie.visible = true ie.navigate "siiprodsrs01.db.sma" while ie.readystate <> readystate_complete loop set htmldoc = ie.document set htmlinput = htmldoc.getelementbyid("what") htmlinput.value = "12345" set htmlbuttons = htmldoc.getelementsbytagname("button") each htmlbutton in htmlbuttons debug.print htmlbutton.classname, htmlbutton.tagname, htmlbutton.id, htmlbutton.innertext next htmlbutton htmlbuttons(0).click end sub
the problem ie readystate never completed state during while, happened me many time, reading online seem ie problem,
sometime helped me
do while ie.busy or ie.readystate <> readystate_complete doevents loop
an alternative declare ie object event , use ie_documentcomplete event:
option explicit 'requires microsoft internet controls reference library dim withevents ie internetexplorer sub start_here() set ie = new internetexplorer ie.visible = true 'first url go, next actions executed in 'webbrowser event sub procedure - documentcomplete ie.navigate "siiprodsrs01.db.sma" end sub private sub ie_documentcomplete(byval pdisp object, url variant) 'pdisp returned explorer object in event 'pdisp.document htmldocument control can use set htmldoc = pdisp.document 'since there no do-loop, have know using reference if instr(1, url, "siiprodsrs01.db.sma") > 0 set htmlinput = pddisp.document.getelementbyid("what") htmlinput.value = "12345" set htmlbuttons = htmldoc.getelementsbytagname("button") each htmlbutton in htmlbuttons debug.print htmlbutton.classname, htmlbutton.tagname, htmlbutton.id, htmlbutton.innertext next htmlbutton htmlbuttons(0).click end if end sub
Comments
Post a Comment