I have written the following procedure to retrieve a .csv file from a website. The procedure works fine, as I use it at other sites to download .csv files on a scheduled basis.
The problem with this particular site, is that for security reasons they change the name of the daily. Today the file might be called PriceList_YWQBW.csv, while tomorrow the file will be something different so I can not point to the URL with the GET command.
To manually go and download the file I am traversed through a log in page and by clicking on a series of links I am presented with a pop up page that says “right click to save target.” I am thinking there has to be a way to traverse through these pages in code.
Thoughts?
Thanks in advance
Private Sub Form_Load()
' Create an instance of the WinHTTPRequest ActiveX object.
Set http = New WinHttpRequest
'HttpRequest SetCredentials flags.
Const HTTPREQUEST_SETCREDENTIALS_FOR_SERVER = 0
' Switch the mouse pointer to an hourglass while busy.
MousePointer = vbHourglass
' Open an HTTP connection.
http.Open "GET", " False
'Set credentials for server.
http.SetCredentials "UserName", "Password", _
HTTPREQUEST_SETCREDENTIALS_FOR_SERVER
' Send the HTTP Request.
http.Send
' Load the contents of the file into a string variable.
file_contents = http.ResponseText
Set http = Nothing
' Save the file
If Not file_contents = "" Then
Open "\\Local Path\Catalog.csv" For Output As #1
Print #1, file_contents
End If
Close
' Switch the mouse pointer back to default.
MousePointer = vbDefault
' Close the form.
Unload Me
End Sub
The problem with this particular site, is that for security reasons they change the name of the daily. Today the file might be called PriceList_YWQBW.csv, while tomorrow the file will be something different so I can not point to the URL with the GET command.
To manually go and download the file I am traversed through a log in page and by clicking on a series of links I am presented with a pop up page that says “right click to save target.” I am thinking there has to be a way to traverse through these pages in code.
Thoughts?
Thanks in advance
Private Sub Form_Load()
' Create an instance of the WinHTTPRequest ActiveX object.
Set http = New WinHttpRequest
'HttpRequest SetCredentials flags.
Const HTTPREQUEST_SETCREDENTIALS_FOR_SERVER = 0
' Switch the mouse pointer to an hourglass while busy.
MousePointer = vbHourglass
' Open an HTTP connection.
http.Open "GET", " False
'Set credentials for server.
http.SetCredentials "UserName", "Password", _
HTTPREQUEST_SETCREDENTIALS_FOR_SERVER
' Send the HTTP Request.
http.Send
' Load the contents of the file into a string variable.
file_contents = http.ResponseText
Set http = Nothing
' Save the file
If Not file_contents = "" Then
Open "\\Local Path\Catalog.csv" For Output As #1
Print #1, file_contents
End If
Close
' Switch the mouse pointer back to default.
MousePointer = vbDefault
' Close the form.
Unload Me
End Sub