URLDownloadToFile looping intermittent success, regular failures

farmerusingexcel

New Member
Joined
Jan 2, 2021
Messages
1
Office Version
  1. 365
Platform
  1. 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
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
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Welcome

Can you post the page address where you click to download one of the zipped files? I need to see the clickable element.
 
Upvote 0

Forum statistics

Threads
1,214,826
Messages
6,121,792
Members
449,048
Latest member
greyangel23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top