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
Bookmarks