Downloading file from web

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 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.

Parents
No Data
Reply
  • What version of CorelDRAW are you using? And from your code it looks to be a 64-bit version.

    I tried your code and it worked fine for me.

    I have some very similar code and it has always worked well for me. Posting here for reference.

    #If VBA7 Then
        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
    #Else
        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
    #End If
    
    Public Function DownloadFile(sSourceUrl As String, sLocalFile As String) As Boolean
       DownloadFile = URLDownloadToFile(0&, _
                                        sSourceUrl, _
                                        sLocalFile, _
                                        BINDF_GETNEWESTVERSION, _
                                        0&) = ERROR_SUCCESS
    End Function
    
    Private Sub DownloadSingleFile()
        Dim sSourceUrl As String, sLocalFile As String
    
        sSourceUrl = "">upload.wikimedia.org/.../Mercedes_V6_DTM_Rennmotor_1996.jpg"
        sLocalFile = "C:\Temp\engine.jpg"
    
        If DownloadFile(sSourceUrl, sLocalFile) Then
            Debug.Print "File downloaded"
        Else
            Debug.Print "File download not downloaded"
        End If
    End Sub
    

    -Shelby

Children