Hi All - I have the below code, which works fine, however it stops running when it hits an empty cell - I need this to run whether the cell has a url or not...(some of the cells are blank or don't have a URL yet... So I need it to run from D10:D1000 regardless. Can someone help me with the code to fix this? Im new to VBA so if you can create the full code with correction - I'd greatly appreciate it!
Code:
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
Public Function DownloadURLtoFile(sSourceURL As String, _
sLocalFileName As String) As Boolean
DownloadURLtoFile = URLDownloadToFile(0&, _
sSourceURL, sLocalFileName, &H10, 0&) = 0&
End Function
Sub DownLoadFiles()
Dim cell As Range, rngListOfURL As Range
Const PTH = "C:\BadgeIcons\" 'this is your save to location
Set rngListOfURL = Sheet16.Range("D10:D1000") 'amend as appropriate
For Each cell In rngListOfURL
If DownloadURLtoFile(cell.Value, PTH & cell.Offset(, 2).Value & ".bmp") Then
cell.Offset(, 50).Value = "Successfully downloaded"
Else
cell.Offset(, 50).Value = "Error - no download"
End If
Next cell
End Sub