VBA Excel extracting data from website with changing date in URL -


i extremely new vba appreciated. trying extract data website https://www.census.gov/construction/bps/txt/tb3u201601.txt. 201601 in url represents jan 2016. create program cycles through months until 2003 , puts data in excel spreadsheet. far have written isolated date (below) cannot figure out how have loop through dates need. again.

sub macro2() ' ' macro2 macro '  ' dim str1 string dim str2 string dim str3 string dim str string  str1 = "url;https://www.census.gov/construction/bps/txt/tb3u" str2 = "201601" str3 = ".txt" str = str1 & str2 & str3  activesheet.querytables.add(connection:= _     str, destination _     :=range("$a$2"))     .name = "tb3u201601_4"     .fieldnames = true     .rownumbers = false     .filladjacentformulas = false     .preserveformatting = true     .refreshonfileopen = false     .backgroundquery = true     .refreshstyle = xlinsertdeletecells     .savepassword = false     .savedata = true     .adjustcolumnwidth = true     .refreshperiod = 0     .webselectiontype = xlalltables     .webformatting = xlwebformattingnone     .webpreformattedtexttocolumns = true     .webconsecutivedelimitersasone = true     .websingleblocktextimport = false     .webdisabledaterecognition = false     .webdisableredirections = false     .refresh backgroundquery:=false end 

end sub

add loop @ parent

sub macro1()     dim startdate date     dim thisdate date     dim enddate date     dim string2 string      startdate = dateserial(2003, 1, 1)     enddate = dateserial(2016, 4, 1)     dim integer              thisdate = dateadd("m", i, startdate)         string2 = format(thisdate,"yyyymm")         call macro2 (string2)         = + 1      loop while (thisdate <= enddate)  end sub 

change macro2 accept string parameter

sub macro2(str2 string) .... 

and remove line in macro2

str2 = "201601" 

Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -