VBA Excel data extracting from a website for different dates with same URL

I need to extract website table data from this link: https://www.iexindia.com/marketdata/areaprice.aspx for different dates. The problem is that even for a different date, the URL of the website remains same as the URL for the current date, So I can not use the dynamic URL in the VBA code. I am getting data only for the current date. Any help is extremely appreciated. Thank you.

1 answer

  • answered 2017-06-17 19:18 Vicky

    I am using this code but its returning data only for the current date. Please help me in creating a loop such that I can extract data for other desired dates also. The problem is that the URL is same even after changing the date, so I can not use the dynamic URL.

    Sub Macro1() ' ' Macro1 Macro ' ' Application.CutCopyMode = False

    Application.CutCopyMode = False
    With ActiveSheet.QueryTables.Add(Connection:= _
        "URL;https://www.iexindia.com/marketdata/areaprice.aspx", Destination:=Range( _
        .Name = "areaprice"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .WebSelectionType = xlEntirePage
        .WebFormatting = xlWebFormattingNone
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
    End With
    Selection.Delete Shift:=xlUp
    ActiveWindow.LargeScroll ToRight:=-1
    Selection.Delete Shift:=xlToLeft
    Selection.Delete Shift:=xlUp

    End Sub