excel - Need to append data to the next blank row instead of creating data in a new worksheet -
i trying download historical stock prices moneycontrol.com. here code have...the current code extracts data each webpage , pastes new worksheet each time.
but, append data next blank row instead of creating data in new worksheet. can please me this?
private const url_template string = "url;http://www.moneycontrol.com/stocks/hist_stock_result.php?sc_id=ri&pno={0}&hdn=daily&fdt=2000-01-01&todt=2015-12-31" private const number_of_pages byte = 1 sub datadownload() dim page byte dim querytableobject querytable dim url string page = 1 number_of_pages url = vba.strings.replace(url_template, "{0}", page) set querytableobject = activesheet.querytables.add(connection:=url, destination:=thisworkbook.worksheets.add.[a1]) querytableobject.fieldnames = true querytableobject.rownumbers = false querytableobject.filladjacentformulas = false querytableobject.preserveformatting = true querytableobject.refreshonfileopen = true querytableobject.backgroundquery = true querytableobject.refreshstyle = xloverwritecells querytableobject.savepassword = false querytableobject.savedata = false querytableobject.adjustcolumnwidth = false querytableobject.refreshperiod = 0 querytableobject.webselectiontype = xlspecifiedtables querytableobject.webformatting = xlwebformattingnone querytableobject.webtables = "4" querytableobject.webpreformattedtexttocolumns = true querytableobject.webconsecutivedelimitersasone = true querytableobject.websingleblocktextimport = true querytableobject.webdisabledaterecognition = true querytableobject.webdisableredirections = true querytableobject.refresh backgroundquery:=false next page end sub
not tested try adding lines:
dim ws worksheet set ws = thisworkbook.sheets("sheetname") ' change actual sheetname
then change line:
set querytableobject = activesheet.querytables.add(connection:=url, _ destination:=thisworkbook.worksheets.add.[a1])
to line:
set querytableobject = ws.querytables.add(connection:=url, _ destination:=ws.range("a:a").find("*", , , , , xlprevious).offset(1, 0))
this way, data added on sheet specified , @ first blank row.
Comments
Post a Comment