0

I need to download CSV file from the below site. When I visit a page, I need to choose drop down option from "View Options Contracts for" and "Expiry Date", then on right side, I get to see CSV file, which is embedded. I used below code, I am unable to download file. Any assistance will be much appreciated.

https://www.nseindia.com/option-chain

Option Explicit
Public Sub testing()
    Dim qt As QueryTable
    Dim ws As Worksheet

    Set ws = ThisWorkbook.Worksheets("Test")

    Const URL As String = "https://www.nseindia.com/option-chain"
    Set qt = ws.QueryTables.Add(Connection:="URL;" & URL, Destination:=ws.Range("A1"))

    With qt
        .RefreshOnFileOpen = True
        .FieldNames = True
        .WebSelectionType = xlSpecifiedTables
        .WebTables = 1
        .Refresh BackgroundQuery:=False
    End With
End Sub
Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
Manish
  • 213
  • 2
  • 6
  • 18
  • 2
    *"I am unable to download file"* is not a useful error description. Also you need to download the csv file before you can use it in `QueryTables`. I recommend to do some research on web scraping with VBA and downloading files from websites (there are a lot of resources in the web and here on SO). Once you downloaded the file to your hard disc you can continue trying to open it with `QueryTables`. – Pᴇʜ May 17 '21 at 06:35
  • 1
    This should help you to advance in filling the dropdowns: https://stackoverflow.com/questions/63294113/automate-ie-via-excel-to-fill-in-a-dropdown-and-continue – ceci May 17 '21 at 08:10

0 Answers0