Kristensen11
New Member
- Joined
- Jul 17, 2018
- Messages
- 7
Hi All,
I need some help regarding downloading a picture and then save it in a folder.
Right now i have the following:
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
Public Function DownloadFile(URL As String, LocalFilename As String) As Boolean
Dim lngRetVal As Long
lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
If lngRetVal = 0 Then
If Dir(LocalFilename) <> vbNullString Then
DownloadFile = True
End If
End If
End Function
Sub Savepicture()
Dim sSourceUrl As String
Dim sLocalFile As String
sSourceUrl = "http://www.image.com/img/home/hero-2.jpg"
sLocalFile = "C:\Users\Jens.Hansen\Desktop\Test\Seaworld"
If DownloadFile(sSourceUrl, sLocalFile) Then
MsgBox "File downloaded successfully", vbInformation
Else
MsgBox "There was a problem downloading the file!", vbInformation
End If
End Sub
However, when i run it, it says that there was a problem downloading the file - what is wrong?
Thank you !
I need some help regarding downloading a picture and then save it in a folder.
Right now i have the following:
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
Public Function DownloadFile(URL As String, LocalFilename As String) As Boolean
Dim lngRetVal As Long
lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
If lngRetVal = 0 Then
If Dir(LocalFilename) <> vbNullString Then
DownloadFile = True
End If
End If
End Function
Sub Savepicture()
Dim sSourceUrl As String
Dim sLocalFile As String
sSourceUrl = "http://www.image.com/img/home/hero-2.jpg"
sLocalFile = "C:\Users\Jens.Hansen\Desktop\Test\Seaworld"
If DownloadFile(sSourceUrl, sLocalFile) Then
MsgBox "File downloaded successfully", vbInformation
Else
MsgBox "There was a problem downloading the file!", vbInformation
End If
End Sub
However, when i run it, it says that there was a problem downloading the file - what is wrong?
Thank you !