Downloading zip file from website using excel vba (if also able to extract the csv from zip file and open it in excel, then even better) -
after quite searching i've not been able make macro download .zip file specific website. mean i've been able find similar problems have not been able apply changes necessary in order problem solved. website contains zip files is: https://nio.gov.si/nio/data/prvic+registrirana+vozila+v+letu+2014+po+mesecih, under table header "priponke" files. example: december 2014 (959 kb), november 2014 (1061 kb), ... url downloads zip file december 2014 "cms/download/document/a7605005b6879fe5f7dbab6d60d4ae787dbced6b-1422453741279". thank in advance , awaiting reply.
my current code is:
public sub downloadfile() dim objwhttp object dim strpath string dim arrdata() byte dim lngfreefile long on error resume next set objwhttp = createobject("winhttp.winhttprequest.5") if err.number <> 0 set objwhttp = createobject("winhttp.winhttprequest.5.1") end if on error goto 0 strpath = "https://nio.gov.si/nio/data/prvic+registrirana+vozila+v+letu+2014+po+mesecih" strpath = "https://nio.gov.si/nio/cms/download/document/a7605005b6879fe5f7dbab6d60d4ae787dbced6b-1422453741279" objwhttp.open "get", strpath, false objwhttp.send arrdata = objwhttp.responsebody if len(dir("c:\footiefile", vbdirectory)) = 0 mkdir "c:\footiefile" end if lngfreefile = freefile open "c:\footiefile\myfile.xml" binary access write #lngfreefile put #lngfreefile, 1, arrdata close #lngfreefile set objwhttp = nothing erase arrdata end sub
kind regards
you need download binary file, , save it. can done using msxml2.xmlhttp60 object download, , adodb.stream object saving.
see e.g. http://www.motobit.com/tips/detpg_read-write-binary-files/
i've used succesfully download jpg files server , display them in ms access front end.
also hope realize can't start url 'cms', need qualified domain name plus resource (aka http:// etc)
also careful unicode data. might need use strconv(). check after downloading size of file same on server.
Comments
Post a Comment