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
Declare
Function
DeleteUrlCacheEntry
Lib
"wininet.dll"
_
Alias
"DeleteUrlCacheEntryA"
( _
ByVal
lpszUrlName
As
String
)
As
Long
Public
Function
FileDownload(
ByVal
sURL
As
String
, _
ByVal
sLocalFile
As
String
, _
Optional
ByVal
bClearCache
As
Boolean
=
True
)
As
Boolean
Dim
lResult
As
Long
If
bClearCache
Then
lResult = DeleteUrlCacheEntry(sURL)
End
If
lResult = URLDownloadToFile(0, sURL, sLocalFile, 0, 0)
FileDownload = (lResult = 0)
End
Function
Private
Sub
Application_Startup()
Dim
sURL
As
String
Dim
sLocalFile
As
String
sLocalFile =
"C:\email\aktion.jpg"
If
FileDownload(sURL, sLocalFile)
Then
Else
MsgBox
"Fehler beim Download: "
& _
"Entweder existiert die URL nicht, oder Sie haben "
& _
"einen ungültigen Dateinamen angegeben!"
, vbCritical
End
If
End
Sub