Requirement:
The user is creating VBA to automatically download files from a password protected webserver.
Solution:
For x = 2 To lastrow For i = 0 To UBound(files) filedate = ThisWorkbook.Sheets(1).Cells(x, 1).Value full_file_path = filepath + filedate + "\" + files(i, 0) + filedate + files(i, 1) a = MkDir(filedate, filepath) fileurl = mainurl + filedate + "/" + files(i, 0) + filedate + files(i, 1) Set WHTTP = CreateObject("WinHTTP.WinHTTPrequest.5.1") 'Then you have to GET direct file url WHTTP.Open "GET", fileurl, False WHTTP.SetCredentials "ad15qy", "Itsmyn80", HTTPREQUEST_SETCREDENTIALS_FOR_SERVER WHTTP.Send FileData = WHTTP.ResponseBody Set WHTTP = Nothing 'Save the file FileNum = FreeFile Open full_file_path For Binary Access Write As #FileNum Put #FileNum, 1, FileData Close #FileNum Next i Next x
Obtained from the OzGrid Help Forum.
Solution provided by eureka18.
See also: Index to Excel VBA Code and Index to Excel Freebies and Lesson 1 - Excel Fundamentals and Index to how to… providing a range of solutions and Index to new resources and reference sheets
See also:
How to use VBA script to count files/subfolders using a range from WB for the root folder |
How to use VBA code to output multiple worksheets to separate workbooks |
How to use VBA code to generate report based on criteria |
How to use Excel VBA code to hide based on criteria |
How to protect VBA source code from view |
How to use VBA to turn columns into rows |
Click here to visit our Free 24/7 Excel/VBA Help Forum where there are thousands of posts you can get information from, or you can join the Forum and post your own questions.