Use of URLDownloadToFile from TeamDeveloper 6.3

Discussion forum about all things Team Developer 5.x and 6.x
monchotgu
Honduras
Posts: 82
Joined: 24 Apr 2017, 02:55
Location: Honduras

Use of URLDownloadToFile from TeamDeveloper 6.3

Post by monchotgu » 04 Mar 2021, 16:59

Hi,I am using team developer 6.3. I have a request from my customer to download some pdf diplomas from TalentLMS. This site gives them an excel file with the link for each employees in order to download the diploma in a pdf file, But they do not have a choice to do a batch download, so they do have to click on each link and do a save as. for each employee. This takes too much time. They are asking if there is a way to do this in a program. I invistigated and found this function: URLDownloadToFile, that aparently can do that, but I do not have to much expirience using functions from windows.
Can anybody help me on how to use this function or if there is an alternative way thet I can "batch:"" download this files with the urls ?

Thank in advance

Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 3384
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

Re: Use of URLDownloadToFile from TeamDeveloper 6.3

Post by Dave Rabelink » 05 Mar 2021, 07:09

Regards,
Dave Rabelink

Image
Articles and information on Team Developer Tips & Tricks Wiki
Download samples, documents and resources from TD Sample Vault
Videos on TDWiki YouTube Channel

Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 3384
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

Re: Use of URLDownloadToFile from TeamDeveloper 6.3

Post by Dave Rabelink » 05 Mar 2021, 07:44

Maybe a better way is to create a VBA macro which loads the Excel file containing the url's and download each defined URL file in a loop.

As an example:

Code: Select all

Private Declare 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

Sub OpenWorkbookLinks()

    Dim wkb As Workbook
    Dim sheet As Worksheet
    Dim x As Integer
    
    ' Open the Excelfile having URLs
    Set wkb = Workbooks.Open("C:\Temp\DownloadLinks.xlsx")
    
    ' Find the sheet containing the URLs. Here the sheet is named "SHEET_URLS"
    Set sheet = wkb.Worksheets("SHEET_URLS")
    
          
    Application.ScreenUpdating = False

    NumRows = sheet.Range("A1", Range("A1").End(xlDown)).Rows.Count

    sheet.Range("A1").Select
    
    ' Set the local download folder
    savepath = "C:\temp\"

    ' Loop through all cells until empty
    For x = 1 To NumRows
        ActiveCell.Offset(1, 0).Select
        URL = ActiveCell.Text

        ' Get the file part of the url (last part after the last forward slash)
        file = Mid$(URL, InStrRev(URL, "/") + 1)
        
        ' Download the file
        URLDownloadToFile 0, URL, savepath & file, 0, 0
    Next
    Application.ScreenUpdating = True

End Sub
Regards,
Dave Rabelink

Image
Articles and information on Team Developer Tips & Tricks Wiki
Download samples, documents and resources from TD Sample Vault
Videos on TDWiki YouTube Channel

monchotgu
Honduras
Posts: 82
Joined: 24 Apr 2017, 02:55
Location: Honduras

Re: Use of URLDownloadToFile from TeamDeveloper 6.3

Post by monchotgu » 05 Mar 2021, 18:21

Thank You Dave for your Fast eresponse!! I will give both solutions a try!!! :D :D :D

Return to “General Discussion”

Who is online

Users browsing this forum: [Ccbot] and 1 guest