vba - Import A CSV File into Excel (Requires Login/Pass) -
i've looked @ dozens of similar topics here without finding i'm looking for. if doing manually, navigate url, given parameters:
when go there, requests username , password in pop-up box, enter, , downloads csv.
this python code works perfectly:
import requests requests.auth import httpbasicauth username = "i_cant_tell_you_guys" password = "definitely_cant_share_this" auth = httpbasicauth(username, password) url = "https://the.website.com/mobile/rest/reportservice/exportreport?name=shared%2fmv+report.ppr&format=csv&showtotals=false&valuedate=today" resp = requests.get(url.format(username, password), auth=auth, verify=false) print resp.content
but can't seem replicate in vba. possible? if not, have excel , python work somehow?
thanks!
edit: several people suggested approach: vba winhttp download file password proteced https website since url i'm pulling isn't actual file url, won't work.
edit: got working. website had certificate mismatch, had tell winhttp ignore ssl errors. here's new code:
sub savefilefromurl() const option_sslerrorignoreflags = 4 const sslerrorflag_ignore_all = 13056 const httprequest_setcredentials_for_server = 0 dim filenum long dim filedata() byte dim whttp object mainurl = "https://website.com" fileurl = "https://website.com/myfile.csv" filepath = "c:\myfile.csv" myuser = "login" mypass = "pass" set whttp = createobject("winhttp.winhttprequest.5.1") whttp.open "post", mainurl, false whttp.setcredentials myuser, mypass, httprequest_setcredentials_for_server whttp.setrequestheader "content-type", "application/x-www-form-urlencoded" whttp.option(option_sslerrorignoreflags) = sslerrorflag_ignore_all whttp.send whttp.open "get", fileurl, false whttp.send filedata = whttp.responsebody set whttp = nothing filenum = freefile open filepath binary access write #filenum put #filenum, 1, filedata close #filenum msgbox "file has been saved!", vbinformation, "success" end sub
now i'm getting "run-time error '75': path/file access error"
Comments
Post a Comment