Download error checker

sassriverrat

Well-known Member
Joined
Oct 4, 2018
Messages
617
I have a macro that runs/calls 10 other macros that download pdfs from specified URLs online.
these aren't big files... like 5-8mb BUT these are coming via a VERY SLOW satellite link...

so if I download 10 pdfs via 11 macros (1 macro that calls each of the 10), is there a way/a macro/piece of code that can be added so resume where one fails? Basically, if, say, download 7 fails, is there a way for the calling macro to restart at the failed macro instead of calling to download all 10 again?

Thanks
 

Some videos you may like

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

jmacleary

Well-known Member
Joined
Oct 5, 2015
Messages
920
Office Version
2007
Platform
Windows
You could have a worksheet with the status of each download - e.g. column A has 1 to 10, column B has success/fail. All you need then it to establish when you want to redo the whole lot (each day?) and at that point set all the column B entries to Fail. Then before executing each of the 10, chaeck the status and skip if its success (use vlookup or a direct cell reference).
 

sassriverrat

Well-known Member
Joined
Oct 4, 2018
Messages
617
So here's what I've got....except I'm missing something simple. I can't get the coding to put a date into F5 (i.e. "updater")...... Ideas?

Code:
Option ExplicitDeclare 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
'WORKS
Private Sub Download1()
Dim URL As String
Dim tstamp As String
Dim Namer As String
Dim Dater As String
'Dim downloadstatus As String
Dim LocalFilePath As String
Dim updater As String
Dim DownloadStatus As Long
With Sheets("Background")
    Namer = .Range("B4")
    URL = .Range("I4")
    DownloadStatus = .Range("F4").Value
    Dater = .Range("E1")
    .Range("F5").Value = updater
End With
    
    If Dater <> URL Then
    tstamp = Format(Now, "mm-dd-yyyy")
        LocalFilePath = Environ("Userprofile") & "\Documents\" & tstamp & Namer & ".pdf"
        DownloadStatus = URLDownloadToFile(0, URL, LocalFilePath, 0, 0)
        If DownloadStatus = 0 Then
            MsgBox "File Downloaded. Check in this path: " & LocalFilePath
            updater = tstamp
        Else
            MsgBox "Download File Process Failed"
        End If
    Else: MsgBox "The most up to date pub has been downloaded"
    End If
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,089,973
Messages
5,411,586
Members
403,380
Latest member
ifog671

This Week's Hot Topics

Top