Results 1 to 11 of 11

Downloading multiple files from Internet

Threaded View

  1. #1
    abhay_547
    Guest

    Downloading multiple files from Internet

    Hi All,

    I got the below code, from this site which downloads only one file at one go. I want the macro which will download multiple files from a list of links reflecting in a list box. I have created a userform which has a listbox which gets populated with all download links from where I want to download files. I need the help to implement the below code into my attached download tool userform.

    Private Declare Function URLDownloadToFile _
      Lib "urlmon.dll" _
        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 DownloadFilefromWeb()
    
      Const E_OUTOFMEMORY As Long = &H8007000E
      Const E_DOWNLOAD_FAILURE As Long = &H800C0002
      
      Dim InitialName As String
      Dim Msg As String
      Dim RegExp As Object
      Dim RetVal As Long
      Dim SaveName As String
      Dim SavePath As String
      Dim URL As String
      
        URL = InputBox("Enter the download URL below.", "Download from Internet")
        If URL = "" Then Exit Sub
        
        Set RegExp = CreateObject("VBScript.RegExp")
          RegExp.IgnoreCase = True
          RegExp.Pattern = "^(.*\/)(.+)$"
          InitialName = RegExp.Replace(URL, "$2")
        Set RegExp = Nothing
          
        If InitialName = "" Or InitialName = URL Then
          MsgBox "Error - Missing File Name"
          Exit Sub
        End If
    
        SavePath = Application.GetSaveAsFilename(InitialName)
        If SavePath = "" Then Exit Sub
        
        RetVal = URLDownloadToFile(0&, URL, SavePath, 0&, 0&)
    
        Select Case RetVal
          Case 0
            Msg = "Download Successful"
          Case E_OUTOFMEMORY
            Msg = "Error - Out of Mmemory"
          Case E_DOWNLOAD_FAILURE
            Msg = "Error - Bad URL or Connection Interrupted"
          Case Else
            Msg = "Unknown Error - " & RetVal
        End Select
        
        MsgBox Msg
        
    End Sub
    Thanks for your help in advance.
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1