I’ve already tried using many different techniques with this… One that works pretty nicely but still ties up code when running is using the api call:
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
and
IF URLDownloadToFile(0, "URL", "FilePath", 0, 0) Then
End If
I’ve also used (Successfully) code to write vbscript from within Excel and then running with it wscript and waiting for the callback. But again this isn’t totally async and still ties up some of the code.
I’d like to have the files download in an event driven class and the VBA code can do other things in a big loop with “DoEvents”. When one file is done it can trigger a flag and the code can process that file while waiting for another.
This is pulling excel files off of an Intranet site. If that helps.
Since I’m sure someone will ask, I can’t use anything but VBA. This is going to be used at the workplace and 90% of the computers are shared. I highly doubt they’ll spring for the business expense of getting me Visual Studio either. So I have to work with what I have.
Any help would be greatly appreciated.
You can do this using xmlhttp in asynchronous mode and a class to handle its events:
http://www.dailydoseofexcel.com/archives/2006/10/09/async-xmlhttp-calls/
The code there is addressing responseText, but you can adjust that to use .responseBody. Here’s a (synchronous) example: