Results 1 to 3 of 3

Image download loop, cannot resolve IF failed..

Threaded View

  1. #1
    Registered User
    Join Date
    11-24-2005
    Posts
    39

    Image download loop, cannot resolve IF failed..

    Greetings

    I'm using the following code to download image files from the web.

    The source of the file and the destination are stored on Sheet1 columns C and D

    I'm stuck on how to trap the success or failure of each loop and color the cell accordingly

    Option Explicit
    
    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
    Private Const BINDF_GETNEWESTVERSION As Long = &H10
    Private Const INTERNET_FLAG_RELOAD As Long = &H80000000
     
    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 CommandButton1_Click()
        Dim sURL As String
        Dim sLocalFile As String
        Dim sDestination As String
        Dim sText As String
        Dim i As Integer
        Dim ws As Worksheet
        
        For i = 4 To 9
        With ws
            Range("B" & i).FormulaR1C1 = "Working...."
            Range("B" & i).Interior.ColorIndex = 6
        
            sText = Sheet1.Range("C" & i).Value
            sURL = sText
            sLocalFile = Sheet1.Range("D" & i).Value
            DownloadFile sURL, sLocalFile
        End With
        'IF successful then
            Range("B" & i).FormulaR1C1 = "Completed"
            Range("B" & i).Interior.ColorIndex = 4
        'Else
        '    Range("B" & i).FormulaR1C1 = "Failed"
        '    Range("B" & i).Interior.ColorIndex = 3
        'End IF      Next i
        
    End Sub
    Last edited by Aurbo; 09-16-2015 at 06:28 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Download image from url and save to folder
    By adtastic in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-09-2015, 05:59 PM
  2. [SOLVED] Image download from links in column A
    By fitkhan in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-21-2014, 02:18 PM
  3. Download, Resolve and Chart Multiple Date Series
    By JohnYard in forum Excel General
    Replies: 0
    Last Post: 02-06-2014, 11:56 AM
  4. [SOLVED] How can I resolve this Run-Time error '1004': Method 'Range' of object '_Worksheet' failed
    By dafella in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-02-2013, 01:16 AM
  5. [SOLVED] Download Image to specific directory
    By marreco in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-31-2013, 03:00 PM
  6. Formula: No of days for which contract remained active in a particular month
    By usama.anwar in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-21-2012, 02:29 PM
  7. [SOLVED] After failed update download, how can I bring back Excel?
    By Virginia in forum Excel General
    Replies: 2
    Last Post: 12-20-2005, 09:40 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1