URL to download a csv file using excel vba

264 views Asked by At

Is there any way I can download the csv file from below link for example. "https://www.nseindia.com/corporates-pit?index=equities&symbol=WABCOINDIA&csv=true"

Tried the below code but no luck.

Private Declare PtrSafe Function URLDownloadToFile Lib "urlmon" _
    Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, _
    ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long

Public Sub Valuebuy()

myfile = "https://www.nseindia.com/corporates-pit?index=equities&symbol=WABCOINDIA&csv=true"

  Dim targetFile As String, targetUrl As String, returnVal As Double
    Target = "https://www.nseindia.com/api/corporates-pit?index=equities&symbol=WABCOINDIA&csv=true"
    strSavePath = "C:\testdownload.txt"
    returnVal = URLDownloadToFile(0, Target, strSavePath, 0, 0)
    If returnVal = 0 Then
        Debug.Print "Download ok!"
    Else
        Debug.Print "Error"
    End If
    
End Sub
0

There are 0 answers