J
jwwarrenva
All,
I have been trying to use the following function based on
msxml2.xmlhttp "get" to automate file downloads from web pages. I
didn't write the code, I copied it from a web page somewhere (sorry, I
don't remember where). The problem is, it doesn't work for large
files. If I attempt to download a largish file, say 5 MB, I only get
about 135 KB.
Any suggestions?
My environment: Microsoft Windows XP Professional 5.1.2600 SP 2,
Excel 2003 SP 2, Internet Explorer 6.0 SP 2.
----- code follows -----
Function SaveWebFile(ByVal vWebFile As String, ByVal vLocalFile As
String) As Boolean
Dim oXMLHTTP As Object, i As Long, vFF As Long, oResp() As Byte
Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP")
oXMLHTTP.Open "GET", vWebFile, False 'Open socket to get the
website
oXMLHTTP.Send 'send request
'Wait for request to finish
Do While oXMLHTTP.readyState <> 4
DoEvents
Loop
oResp = oXMLHTTP.responseBody 'Returns the results as a byte array
'Create local file and save results to it
vFF = FreeFile
If Dir(vLocalFile) <> "" Then Kill vLocalFile
Open vLocalFile For Binary As #vFF
Put #vFF, , oResp
Close #vFF
'Clear memory
Set oXMLHTTP = Nothing
End Function
----- end code -----
Thanks in advance,
John Warren
I have been trying to use the following function based on
msxml2.xmlhttp "get" to automate file downloads from web pages. I
didn't write the code, I copied it from a web page somewhere (sorry, I
don't remember where). The problem is, it doesn't work for large
files. If I attempt to download a largish file, say 5 MB, I only get
about 135 KB.
Any suggestions?
My environment: Microsoft Windows XP Professional 5.1.2600 SP 2,
Excel 2003 SP 2, Internet Explorer 6.0 SP 2.
----- code follows -----
Function SaveWebFile(ByVal vWebFile As String, ByVal vLocalFile As
String) As Boolean
Dim oXMLHTTP As Object, i As Long, vFF As Long, oResp() As Byte
Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP")
oXMLHTTP.Open "GET", vWebFile, False 'Open socket to get the
website
oXMLHTTP.Send 'send request
'Wait for request to finish
Do While oXMLHTTP.readyState <> 4
DoEvents
Loop
oResp = oXMLHTTP.responseBody 'Returns the results as a byte array
'Create local file and save results to it
vFF = FreeFile
If Dir(vLocalFile) <> "" Then Kill vLocalFile
Open vLocalFile For Binary As #vFF
Put #vFF, , oResp
Close #vFF
'Clear memory
Set oXMLHTTP = Nothing
End Function
----- end code -----
Thanks in advance,
John Warren