hi, to all of you reading my post,
i know a lot of ppl already struggled with this what i go thru now, i wonder how ppl handled it,
i need to download a file from a website everyday in the morning, the webpage require a user and password, the file is a csv file, i got a code which will download a file from web but not when it require log-in, is there any way to add some coding which will log-in and do my work?
here is my code;
Sub Test()
Dim FileNum As Long
Dim FileData() As Byte
Dim MyFile As String
Dim WHTTP As Object
On Error Resume Next
Set WHTTP = CreateObject("WinHTTP.WinHTTPrequest.5")
If Err.Number <> 0 Then
Set WHTTP = CreateObject("WinHTTP.WinHTTPrequest.5.1")
End If
On Error GoTo 0
MyFile = "http://www.mywebsite.com/cvs_export.php"
WHTTP.Open "GET", MyFile, False
WHTTP.send
FileData = WHTTP.ResponseBody
Set WHTTP = Nothing
If Dir("C:\MyDownloads", vbDirectory) = Empty Then MkDir "C:\MyDownloads"
FileNum = FreeFile
Open "C:\MyDownloads\inventory.csv" For Binary Access Write As #FileNum
Put #FileNum, 1, FileData
Close #FileNum
MsgBox "Open the folder [ C:\MyDownloads ] for the downloaded file..."
End Sub
i know a lot of ppl already struggled with this what i go thru now, i wonder how ppl handled it,
i need to download a file from a website everyday in the morning, the webpage require a user and password, the file is a csv file, i got a code which will download a file from web but not when it require log-in, is there any way to add some coding which will log-in and do my work?
here is my code;
Sub Test()
Dim FileNum As Long
Dim FileData() As Byte
Dim MyFile As String
Dim WHTTP As Object
On Error Resume Next
Set WHTTP = CreateObject("WinHTTP.WinHTTPrequest.5")
If Err.Number <> 0 Then
Set WHTTP = CreateObject("WinHTTP.WinHTTPrequest.5.1")
End If
On Error GoTo 0
MyFile = "http://www.mywebsite.com/cvs_export.php"
WHTTP.Open "GET", MyFile, False
WHTTP.send
FileData = WHTTP.ResponseBody
Set WHTTP = Nothing
If Dir("C:\MyDownloads", vbDirectory) = Empty Then MkDir "C:\MyDownloads"
FileNum = FreeFile
Open "C:\MyDownloads\inventory.csv" For Binary Access Write As #FileNum
Put #FileNum, 1, FileData
Close #FileNum
MsgBox "Open the folder [ C:\MyDownloads ] for the downloaded file..."
End Sub