Here I changed a bit a code I used to download files back in time
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" _
(ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, _
ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Sub DownloadCSV(strFileName As String, strDownloadPath As String)
Dim strLocalFileName As String
Dim strBaseURL As String
Dim strURL As String
Dim bDownloaded As Boolean
strBaseURL = "https://hirds.niwa.co.nz/data/"
strURL = strBaseURL & strFileName
If Right(strDownloadPath, 1) <> "\" Then
strDownloadPath = strDownloadPath & "\"
End If
strLocalFileName = strDownloadPath & strFileName
bDownloaded = URLDownloadToFile(0, strURL, strLocalFileName, 0, 0) = 0
If bDownloaded Then
Call MsgBox("File " & strFileName & " downloaded at " & strDownloadPath, vbInformation, "Success")
Else
Call MsgBox("Error downloading file " & strFileName & " downloaded at " & strDownloadPath, vbCritical, "Error")
End If
End Sub
Sub TestDownloadWork()
Call DownloadCSV("work.csv", "C:\somefolder\")
End Sub
Note that you that file generated is cached for some time and can be downloaded later on... I don't know how they solve naming conflicts. e.g. I was able to download data for location home generated on May 31st: https://hirds.niwa.co.nz/data/home.csv
If the file does not exists, you get 404 error
Bookmarks