farmerusingexcel
New Member
- Joined
- Jan 2, 2021
- Messages
- 1
- Office Version
- 365
- Platform
- Windows
Hi guys many thanks for the forum
I am trying to download historical rainfall figures for a meteorology station with dynamic station names and years (these aren't issues at the moment). Unfortunately the website changes addresses daily for bulk historical rainfall downloads and as such leaves downloading only the individual years as zipped files. Anyway, the download works fine when addresses are cut and pasted into a browser however when using vba URLDownloadToFile it only has intermittent successes and fails with most requests
Still mostly fails with my firewall off, could it be on meteorology site end? Need a delay in my code? Any help appreciated code as below
I am trying to download historical rainfall figures for a meteorology station with dynamic station names and years (these aren't issues at the moment). Unfortunately the website changes addresses daily for bulk historical rainfall downloads and as such leaves downloading only the individual years as zipped files. Anyway, the download works fine when addresses are cut and pasted into a browser however when using vba URLDownloadToFile it only has intermittent successes and fails with most requests
Still mostly fails with my firewall off, could it be on meteorology site end? Need a delay in my code? Any help appreciated code as below
VBA Code:
Private Declare PtrSafe 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 download_historical_rainfall()
Dim year As Long
Dim status As Boolean
Dim msg As String
For year = 2000 To 2020
'station # will be dynamic when done
'the loop works fine, generated links are correct
'why doesnt it work? Something on BOM end maybe or firewall etc
link = "http://www.bom.gov.au/tmp/cdio/IDCJAC0009_010647_" + CStr(year) + ".zip"
status = URLDownloadToFile(0, link, "C:\users\ballb\desktop\historical rainfall\" + CStr(year) + ".zip", 0, 0)
If status = False Then
msg = CStr(year) + "download successful :)"
End If
If status = True Then
msg = CStr(year) + " download failed :("
End If
'from dans bag of tricks
Debug.Print "http://www.bom.gov.au/tmp/cdio/IDCJAC0009_010647_" + CStr(year) + ".zip"
Debug.Print msg
Next year
Debug.Print "-------------------------"
End Sub