Results 1 to 3 of 3

Thread: Download error checker
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    Oct 2018
    Posts
    530
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Default Download error checker

    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

  2. #2
    Board Regular jmacleary's Avatar
    Join Date
    Oct 2015
    Location
    at a desk in the UK
    Posts
    629
    Post Thanks / Like
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Download error checker

    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).
    If my answer has helped, please vote using the Thanks or Like buttons on the left.
    John

  3. #3
    Board Regular
    Join Date
    Oct 2018
    Posts
    530
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Download error checker

    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

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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