Results 1 to 4 of 4

webscrape file download hangs up in sending to folder

Threaded View

  1. #1
    Registered User
    Join Date
    09-22-2011
    Location
    New Jersey
    MS-Off Ver
    Excel 2010
    Posts
    38

    webscrape file download hangs up in sending to folder

    I'm a bit lost on why this particular code gets hung up, it's supposed to webscrape for .xlsm files that reside via a particular api path. I'm trying to have the code go through a list of identifiers/variables, build the urls and download the file and store it locally.

    It seems to get hung up in the Docxlsm.send part, or at least when I interrupt the process that's where the debug/error sends me. This particular code I have modified from another webscrape tool I built , but it was for a different api and it was downloading csv files, not .xlsm, and it works fine.

    Option Explicit
    
    
    Sub NJ_DCA_Muni_Budget_Download()
        Dim Sh As Worksheet
        Dim Rng As Range
        Dim Cell As Range
        Dim DCAcode As String
        Dim year As String
        Dim StrURL As String
        Set Sh = Worksheets("NJDCAcode")
        Set Rng = Sh.Range("c2:c" & Sh.Range("A65536").End(xlUp).Row)
        For Each Cell In Rng
            DCAcode = Cell.Value
            year = Sh.Range("D1")
    
            
            StrURL = "http://www.state.nj.us/dca/divisions/dlgs/resources/fiscal_docs/"
            StrURL = StrURL & year & "_data/" & year & "_fba/" & DCAcode & "_fba_" & year & ".xlsm"
            
            Debug.Print StrURL
            
            DownLoadIntoFolder StrURL, DCAcode & "FY" & year
       
        Next Cell
       
        
    End Sub
    
    Sub DownLoadIntoFolder(URL As String, FileName As String)
    Dim Docxlsm As Object, StreaMFile As Object
    Dim Filepath As String
    Filepath = Range("E1")
    
    
    Set Docxlsm = CreateObject("WinHTTP.WinHTTPRequest.5.1")
    
    
    Docxlsm.Open "GET", URL, False
    
    Docxlsm.send
    
    Set StreaMFile = CreateObject("ADODB.Stream")
    
        With StreaMFile
        .Type = 1
        .Open
        .Write Docxlsm.responseBody
        .SaveToFile Filepath & FileName & ".xlsm", 2
        'file path is determined where this module is saved and the folder as to which report year is being retrieved
        'the folder needs to be established prior to running the code, i.e. if your retrievng "2017" data - that folder needs to exist etc.
        .Close
        
        End With
    Set StreaMFile = Nothing
    Set Docxlsm = Nothing
    End Sub
    Another secondary challenge: I've seen it done before but i do not know how to establish it. I know for the list of my identifiers certain ones will not yield a downloadable .xlsm file because it doesn't exist yet. how can i instruct this process to continue down the list, and keep a record or log of the identifiers that don't retrieve anything, or at least cause a problem?

    Any help in further understanding is greatly appreciated.
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Sending A Word File With Hyperlinks Which Are Linked To The Files In A Folder
    By zanshin777 in forum Word Formatting & General
    Replies: 3
    Last Post: 08-04-2016, 06:40 PM
  2. Download internet file to the specific folder
    By HerryMarkowitz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-07-2015, 08:17 AM
  3. macro to download file into unique folder based on cell value
    By mlicurse in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-11-2014, 01:25 PM
  4. Saving CSV file and sending to a folder over and over again
    By scottymelloty in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-14-2009, 08:56 AM
  5. Download data from folder
    By Sharp in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-25-2008, 05:03 AM
  6. download files in folder
    By Sharp in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-22-2008, 11:54 AM
  7. Replies: 1
    Last Post: 08-23-2005, 02:05 PM

Tags for this Thread

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