-
2
- #1
I am trying to download a file from a website. I got this code off of tek-tips and it works great. The only problem i have is that if the file doesnt exist it shouldnt show a "File Not Found" messagbox.
I have not be able to figure out how to trap this error
oharab (Programmer) Oct 3, 2003
Typical, 2 minutes after you say you can't find it, you find it:
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
Private Const ERROR_SUCCESS As Long = 0
Public Function DownloadFile(sSourceUrl As String, _
sLocalFile As String) As Boolean
'if the API returns ERROR_SUCCESS (0),
'return True from the function
DownloadFile = URLDownloadToFile(0&, _
sSourceUrl, _
sLocalFile, _
0&, _
0&) = ERROR_SUCCESS
End Function
call it like:
DownloadFile "
and your file will be saved onto the c:\ drive.
hth
Ben
----------------------------------------------
Ben O'Hara
"Where are all the stupid people from...
...And how'd they get so dumb?"
NoFX-The Decline
----------------------------------------------
Thanks for the help
Jon Dabrowski
I have not be able to figure out how to trap this error
oharab (Programmer) Oct 3, 2003
Typical, 2 minutes after you say you can't find it, you find it:
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
Private Const ERROR_SUCCESS As Long = 0
Public Function DownloadFile(sSourceUrl As String, _
sLocalFile As String) As Boolean
'if the API returns ERROR_SUCCESS (0),
'return True from the function
DownloadFile = URLDownloadToFile(0&, _
sSourceUrl, _
sLocalFile, _
0&, _
0&) = ERROR_SUCCESS
End Function
call it like:
DownloadFile "
and your file will be saved onto the c:\ drive.
hth
Ben
----------------------------------------------
Ben O'Hara
"Where are all the stupid people from...
...And how'd they get so dumb?"
NoFX-The Decline
----------------------------------------------
Thanks for the help
Jon Dabrowski