Hello forum members,
I am on a lookout to download some files for a table of links. Table is 1 Column X 13 rows
I need vba to catch hold of each row, copy its contents & download the files from links.
I did collect codes from various places. The block for downloading the content has worked for me in my earlier project.
But I don't get how to marry it with table looping................request forum members to help me correct the code.
Below is the code to best of my understanding.
Thanks a lot in advance for the support
Sub download_files()
Dim tbl As ListObject
Dim x As Long
Dim myURL As String
Set tbl = ActiveSheet.ListObjects("derivatives_links")
'Loop Through Every Row in Table
For x = 1 To tbl.Range.Rows.Count
myURL = "cell.Value"
Dim HttpReq As Object
Set HttpReq = CreateObject("Microsoft.XMLHTTP")
With HttpReq
.Open "GET", myURL1, False, "username", "password"
.setRequestHeader "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT"
.send
Debug.Print StrConv(.responseBody, vbUnicode)
If HttpReq.Status = 200 Then
Set oStrm = CreateObject("ADODB.Stream")
oStrm.Open
oStrm.Type = 1
oStrm.Write HttpReq.responseBody
oStrm.SaveToFile ThisWorkbook.Path & "\derivatives_records, 2 ' 1 = no overwrite, 2 = overwrite"
oStrm.Close
End If
End With
Next x
End Sub
Bookmarks