excel vba - Dynamic URL with cell value -
i have code extract team information using dynamic url changes based on cell value.
i keep getting run time error "91" saying "object variable or block variable not set" , when debug points line
set tr_coll = tbl(0).getelementsbytagname("tr")
this code works other data extractions reason giving me error now.
sub vs() dim src worksheet, tgt worksheet dim url string, team1 string dim team2 string, j integer, row integer dim xmlhttp object, html object dim tr_coll object, tr object dim td_coll object, td object set src = sheets("match-up") set tgt = sheets("vs") team1 = src.range("b1") team2 = src.range("aa1") url = "http://www.premierleague.com/en-gb/matchday/matches/2015-2016/epl.past-meetings.html/" & team1 & "-vs-" & team2 set xmlhttp = createobject("msxml2.xmlhttp") xmlhttp.open "get", url, false xmlhttp.send set html = createobject("htmlfile") html.body.innerhtml = xmlhttp.responsetext set tbl = html.getelementsbytagname("table") set tr_coll = tbl(0).getelementsbytagname("tr") each tr in tr_coll j = 1 set td_col = tr.getelementsbytagname("td") each td in td_col cells(row + 1, j).value = td.innertext j = j + 1 next row = row + 1 next end sub
it means tbl variable set nothing. suggests me have hit 404 page doesn't have tables expect.
make sure teams returning valid page. works me using :
url = "http://www.premierleague.com/en-gb/matchday/matches/2015-2016/epl.past-meetings.html/southampton-vs-west-ham"
btw, mispelt td_col 1 'l'(but doesnt matter since you're not using option explicit careful of that!!). don't declare tbl variable doesnt affect since don't use option explicit. means have declare lots of variables - cannot change type, if ever going code vba, suggest option.
step through code f8, , see team strings evaluating to. hardcode in resulting string browser , see happens...
Comments
Post a Comment