excel - Need macro to take the parameter in the url to be taken from the cell -
i macro take sc_id parameter in url taken cell '[data download.xlsx]data'!$b$1. please me modify code??
private const number_of_pages byte = 8 sub datadownload() dim url_template string url_template = "url;http://www.moneycontrol.com/stocks/hist_stock_result.php?sc_id=" _ & ws.range("b1").value2 & "&pno={0}&hdn=daily&fdt=2000-01-01&todt=2015-12-31" dim page byte dim querytableobject querytable dim url string dim ws worksheet set ws = thisworkbook.sheets("data") page = 1 number_of_pages url = vba.strings.replace(url_template, "{0}", page) set querytableobject = ws.querytables.add(connection:=url, _ destination:=ws.range("a:a").find("*", , , , , xlprevious).offset(1, 0)) 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
if you're getting value in same worksheet you're adding querytables
to, can try adding line before you're loop.
edit2:
remove line:
private const url_template string = "url;http://www.moneycontrol...."
declare url_template
variable instead inside sub:
dim url_template string url_template = "url;http://www.moneycontrol.com/stocks/hist_stock_result.php?sc_id=" _ & ws.range("b1").value2 & "&pno={0}&hdn=daily&fdt=2000-01-01&todt=2015-12-31"
then inside loop, use original code set url
.
url = vba.strings.replace(url_template, "{0}", page)
i hope nail time.
Comments
Post a Comment