Hi,
I am trying to download an image from the web using VBA code like:
Private Declare PtrSafe Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" ( _ ByVal pCaller As LongPtr, _ ByVal szURL As String, _ ByVal szFileName As String, _ ByVal dwReserved As LongPtr, _ ByVal lpfnCB As LongPtr) As LongPtr Sub DownloadSingleFile() FileURL = "">upload.wikimedia.org/.../Mercedes_V6_DTM_Rennmotor_1996.jpg" DestinationFile = "C:\my files\engine.jpg" If URLDownloadToFile(0, FileURL, DestinationFile, 0, 0) = 0 Then Debug.Print "File downloaded" Else Debug.Print "File download not downloaded" End IfEnd Sub
Private Declare PtrSafe Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" ( _
ByVal pCaller As LongPtr, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As LongPtr, _
ByVal lpfnCB As LongPtr) As LongPtr
Sub DownloadSingleFile()
FileURL = "">upload.wikimedia.org/.../Mercedes_V6_DTM_Rennmotor_1996.jpg"
DestinationFile = "C:\my files\engine.jpg"
If URLDownloadToFile(0, FileURL, DestinationFile, 0, 0) = 0 Then
Debug.Print "File downloaded"
Else
Debug.Print "File download not downloaded"
End If
End Sub
When I run this code in Excel, it downloads the file, but same code does not download file in CorelDraw. What could be possibly wrong?
Thanks in advance for your help.
Kind Regards.
you can get value from URLDownloadToFile function and check errors.
lRet = URLDownloadToFile(0, FileURL, DestinationFile, 0, 0)
if lRet <> 0 then
If lRet = E_OUTOFMEMORY Then Debug.Print "The buffer length is invalid or there was insufficient memory to complete the operation."
...
Thanks shark_, but what could be the solution then?
check error code from URLDownloadToFile, check path to your destination file. And try to change
LongPtr to Long