hi,
I got following vba code wherein i just need to link url "https://www.nseindia.com/api/corpor...m_date=05-04-2020&to_date=05-05-2020&csv=true" to a cell reference because this link will change on daily basis. please provide a vba for same
>>> use code - tags <<<
I got following vba code wherein i just need to link url "https://www.nseindia.com/api/corpor...m_date=05-04-2020&to_date=05-05-2020&csv=true" to a cell reference because this link will change on daily basis. please provide a vba for same
>>> use code - tags <<<
Code:
Sub TestDown()
DownloadFile "https://www.nseindia.com/api/corporate-board-meetings?index=equities&from_date=05-04-2020&to_date=05-05-2020&csv=true", "C:\test.csv"
End Sub
Function DownloadFile(myURL As String, saveToPath As String)
Dim WinHttpReq As Object
Dim iTimer As Long
Set WinHttpReq = CreateObject("Microsoft.XMLHTTP")
WinHttpReq.Open "GET", myURL, False, "username", "password"
Debug.Print WinHttpReq.readystate
WinHttpReq.send
'make sure readystate is finished
iTimer = Timer
Do While WinHttpReq.readystate = 1
'if 10 seconds elapse and nothing happens, abort:
If Timer - iTimer > 10 Then Exit Do
Loop
'readystate 4 = all data received
If WinHttpReq.readystate = 4 Then
If WinHttpReq.Status = 200 Then
Set oStream = CreateObject("ADODB.Stream")
oStream.Open
oStream.Type = 1
oStream.Write WinHttpReq.responseBody
oStream.SaveToFile saveToPath, 2 ' 1 = no overwrite, 2 = overwrite
oStream.Close
MsgBox ("Download Complete")
Else
MsgBox ("HTTP error: " & WinHttpReq.Status)
End If
Else
MsgBox ("Couldn't get file")
End If
Set oStream = Nothing
Set WinHttpReq = Nothing
End Function
Last edited by a moderator: