Results 1 to 8 of 8

Auto-Download Multiple tables from Excel's URL list

Threaded View

  1. #1
    Registered User
    Join Date
    03-29-2024
    Location
    Nigeria
    MS-Off Ver
    Office2016
    Posts
    4

    Auto-Download Multiple tables from Excel's URL list

    Hello, VBA gurus,
    I am a VBA learner. I need an assistance on how to download bulk of tables from a website automatically. I was told an excel VBA can perform the logic. I have the list of all the URLs of the pages which contain the tables. The workbook for the list is attached. From the list, I want a VBA script that will pick the URL one after the other in column B as shown, open, download and save it with the title in column A as shown in a folder on the window ("C:\Users\Akinyele\Desktop\Stock HV").
    I have copied so many scripts online like the one below, but it has not been working. Your help will be greatly appreciated. Thanks.

    Option Explicit
    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
    
    Dim Ret As Long
    
    '~~> This is where the table will be saved. Change as applicable
    Const ParentFolderName As String = "C:\Users\Akinyele\Desktop\Stock HV"
    
    Sub Sample()
        Dim ws As Worksheet
        Dim LastRow As Long, i As Long
        Dim Folderpath, strPath As String
    
        Set ws = Sheets("Sheet1")
    
        LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row
    
        For i = 1 To LastRow
      
            Folderpath = ParentFolderName & ws.Range("A" & i).Value & ""
      
            If Len(Dir(Folderpath, vbDirectory)) = 0 Then
                MkDir Folderpath
            End If
      
            strPath = Folderpath & "File" & i & ".csv"
            Ret = URLDownloadToFile(0, ws.Range("B" & i).Value, strPath, 0, 0)
    
            If Ret = 0 Then
                ws.Range("C" & i).Value = "File successfully downloaded"
            Else
                ws.Range("C" & i).Value = "Unable to download the file"
            End If
    
        Next i
    
    End Sub
    Attached Files Attached Files
    Last edited by alansidman; 03-31-2024 at 02:22 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Macro to download data from two tables to one excel sheet
    By nawalanek1 in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 03-16-2023, 06:04 AM
  2. VBA to Download SharePoint List to Excel
    By Mike Savage in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-27-2020, 10:38 AM
  3. Creating multiple forms with auto-populated fields, data validation and excel tables
    By gilliamwibson in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-18-2016, 04:26 PM
  4. Replies: 0
    Last Post: 01-15-2016, 09:20 AM
  5. Macro to download tables from multiple webpages
    By newbieatexcel in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-02-2015, 02:23 AM
  6. after auto download all files in an excel , file names get crazy!!help!!!
    By guanliangsky in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-08-2012, 05:15 PM
  7. Auto table feature in excel doesnt work on multiple tables
    By Chris Lampard in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 05-26-2006, 08:25 AM

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