excel - VBA Object Required Error Trying To Get InnerText -
i trying create code go website, put in data, submit it, , return answer cell in excel. when step through it, works fine, when try run it, run-time error 424; object required.
i tried looking answer, not grasping on how quite fix this. issue? how correct it?
sub distance() dim ie object ' create internetexplorer object set ie = createobject("internetexplorer.application") ' make visible ie.visible = true ' go site ie.navigate "http://www.distance-cities.com/" ' wait while ie loading... until ie.readystate = 4 doevents loop ie.document.getelementbyid("from").value = "stillwater, ok" ie.document.getelementbyid("to").value = "hollis, ok" ie.document.forms(0).submit until ie.readystate = 4 doevents loop '*below error sheet1.range("e5").value = ie.document.getelementbyid("routemi").innertext ie.quit end sub
i apologize if bit messy.
thanks help!
something (untested):
dim el object '... set el = waitforelement(ie.document, "routemi", 1) if not el nothing sheet1.range("e5").value = el.innertext else msgbox "element 'routemi' not found!" exit sub end if
utility function element id, waiting until appears:
function waitforelement(doc object, id string, maxwaitsec double) object dim rv object, t t = timer set rv = doc.getelementbyid(id) doevents loop while rv nothing , (timer - t) < maxwaitsec set waitforelement = rv end function
Comments
Post a Comment