Excel VBA - Downloading/renaming/saving a link based on specific segments of text

Hawk11ns

Board Regular
Joined
Jul 21, 2015
Messages
61
Office Version
  1. 365
Platform
  1. Windows
The code below downloads, renames, and saves a zip file based on a specific URL, defined as 'myUrl', and was meant to only serve as a placeholder while the macro was being written. Now, it needs to be modified so that the file being downloaded is selected from a list of files based on segments of the file name (highlighted below) which include the date (today's date), the posting time (between 0700 and 0800), and the zip content type (_csv). This is because these files are on a rolling update and fall off. Note, the file names - or "Titles" - are not, in fact, the the actual file names when examining the download links (see below for example).

Example of title versus download link:
Title:
cdr.00012311.0000000000000000.20200918.073000627.LFCCONGESTNP3560_csv.zip
Download Link:
How can I have VBA examine the list of links on this page and download the link associated with the file name which meets the aforementioned conditions?

Link to file list: ERCOT MIS

1600448186225.png



VBA Code:
Sub get12311()
'Report ID# 12311 - Seven-Day Load Forecast by Forecast Zone
    
    Dim myURL As String
    myURL = "http://mis.ercot.com/misdownload/servlets/mirDownload?mimic_duns=000000000&doclookupId=734483955"

    Dim WinHttpReq As Object
    Set WinHttpReq = CreateObject("Microsoft.XMLHTTP")
    WinHttpReq.Open "GET", myURL, False
    WinHttpReq.send

    myURL = WinHttpReq.responseBody
        If WinHttpReq.Status = 200 Then
            Set oStream = CreateObject("ADODB.Stream")
            oStream.Open
            oStream.Type = 1
            oStream.Write WinHttpReq.responseBody
            oStream.SaveToFile ("C:\Users\Hawki\Documents\Staging_Un\12311\12311.zip")
            oStream.Close
        End If
    
End Sub
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

Forum statistics

Threads
1,224,823
Messages
6,181,185
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top