automation - I am confused by this object required error VBA -


i have been working on vba code long time. goal copy excel document, search online, , pull html code. keep getting error code says "object required" , says "object variable or block variable not set." focused on line "set elementtwo = elementone.item(i).innertext

i have tried deleting word "set" have tried changing elementtwo string. weird piece for...next loop won't let me "exit for." returns error. have tried few other things no avail. appreciated

option explicit option compare text  public enum readystate     readystate_uninitialized = 0     readystate_loading = 1     readystate_loaded = 2     readystate_interactive = 3     readystate_complete = 4 end enum  sub getcategory()  dim rowno, colno, integer dim parent, item, url1, url2, url3 string dim objhtml object dim elementone object dim elementtwo string   rowno = 3 colno = 5  url1 = "http://www.infores.com/public/us/knowledgegroup/resources/resources.pli?defaultdatatype=&pageid=validatorresults&upc1=" url2 = "&upc2=" url3 = "&submitupc=find+it%21"  dim ie object set ie = createobject("internetexplorer.application")       worksheets(1)     while rowno <= 5         parent = cells(rowno, colno)         item = cells(rowno, colno + 1)          ie             .navigate url1 & parent & url2 & item & url3             .visible = false          'delay while ie loads         while (ie.busy or ie.readystate <> readystate.readystate_complete)             doevents         loop              'put html code in document object             set objhtml = .document             doevents         end           set elementone = objhtml.getelementsbytagname("td") 'break down html code              = 1 elementone.length                 elementtwo = elementone.item(i).innertext                 if elementtwo = "description"              'find category                     cells(rowno, colno + 4) = elementone.item(i + 1).innertext    'put category excel                 end if                 next               doevents             ie.quit             rowno = rowno + 1     wend  end end sub 

this think want, processes loop fails during it. can atleast debug , see why:

option explicit option compare text  public enum readystate     readystate_uninitialized = 0     readystate_loading = 1     readystate_loaded = 2     readystate_interactive = 3     readystate_complete = 4 end enum  sub getcategory()  dim rowno, colno, integer dim parent, item, url1, url2, url3 string dim objhtml object, elementone object, elementtwo string   rowno = 3 colno = 5  url1 = "http://www.infores.com/public/us/knowledgegroup/resources/resources.pli?defaultdatatype=&pageid=validatorresults&upc1=" url2 = "&upc2=" url3 = "&submitupc=find+it%21"  dim ie object 'set ie = createobject("internetexplorer.application")   worksheets(1)     while rowno <= 5         parent = cells(rowno, colno)         item = cells(rowno, colno + 1)          set ie = createobject("internetexplorer.application")          ie             .navigate url1 & parent & url2 & item & url3             .visible = false          'delay while ie loads         while (ie.busy or ie.readystate <> readystate.readystate_complete)             doevents         loop              'put html code in document object             set objhtml = .document             doevents         end           set elementone = objhtml.getelementsbytagname("td") 'break down html code              = 0 elementone.length - 1                 elementtwo = elementone(i).innertext                 if elementtwo = "description"              'find category                     cells(rowno, colno + 4) = elementone(i + 1).innertext  'put category excel                 end if             next               doevents             ie.quit             rowno = rowno + 1     wend  end end sub 

Comments