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