Consulting

Results 1 to 6 of 6

Thread: Solved: extract data from website to excel

  1. #1
    VBAX Contributor
    Joined
    Apr 2012
    Posts
    107
    Location

    Solved: extract data from website to excel

    In I1, put formula =TEXT(J1)
    In J1 ,put ^DJI,say. What's wrong with the following code ,plse?
    With Worksheets("Sheet1").QueryTables.Add(Connection:= _ "URL;http://ichart.finance.yahoo.com/table.csv?s=" & Cells(1, "I")&a=08&b=13&c=2011&d=06&e=6&f=2013&g=w&ignore=.xlsx"

  2. #2
    VBAX Expert Tinbendr's Avatar
    Joined
    Jun 2005
    Location
    North Central Mississippi (The Pines)
    Posts
    993
    Location
    Can you show us the direct link?

    David


  3. #3
    VBAX Expert Tinbendr's Avatar
    Joined
    Jun 2005
    Location
    North Central Mississippi (The Pines)
    Posts
    993
    Location
    I think I got it. You had left the Destination range off, and there was a missing quote.

    [vba]With Worksheets("Sheet2").QueryTables.Add(Connection:= _
    "URL;http://ichart.finance.yahoo.com/table.csv?s=" _
    & Sheet2.Cells(1, "I").Value & "&a=08&b=13&c=2011&d=06&e=6&f=2013&g=w&ignore=.csv", _
    Destination:=Sheet2.Range("a1"))[/vba]
    I tried it without the qualified range (Sheet2.Cells(1, "I").Value vs Cells(1, "I") ), but it would error out.

    I couldn't get the xlsx extension to work either,

    HTH

    David


  4. #4
    VBAX Contributor
    Joined
    Apr 2012
    Posts
    107
    Location
    [VBA]On Error Resume Next
    ThisWorkbook.Connections(1).Delete
    Err.Clear: On Error Goto 0
    With Worksheets("Sheet1").QueryTables.Add(Connection:= _
    "URL;http://ichart.finance.yahoo.com/table.csv?s=^STI&a=08&b=13&c=2011&d=06&e=6&f=2013&g=w&ignore=.xlsx _
    , Destination:=Range("$A$1"))
    .Name = _
    "MyData"
    .FieldNames = True
    .RowNumbers = False
    .FillAdjacentFormulas = False
    .PreserveFormatting = True
    .RefreshOnFileOpen = False
    .BackgroundQuery = True
    .RefreshStyle = 0
    .SavePassword = False
    .SaveData = True
    .AdjustColumnWidth = True
    .RefreshPeriod = 0
    .WebSelectionType = xlSpecifiedTables
    .WebFormatting = xlWebFormattingNone
    .WebTables = "4"
    .WebPreFormattedTextToColumns = True
    .WebConsecutiveDelimitersAsOne = True
    .Refresh BackgroundQuery:=False
    End With [/VBA]

  5. #5
    VBAX Expert Tinbendr's Avatar
    Joined
    Jun 2005
    Location
    North Central Mississippi (The Pines)
    Posts
    993
    Location
    [VBA]With Worksheets("Sheet1").QueryTables.Add(Connection:= _
    "URL;http://ichart.finance.yahoo.com/table.csv?s=" & _
    Worksheets("Sheet1").Range("J1").Value & "&a=08&b=13&c=2011&d=06&e=6&f=2013&g=w&ignore=.xlsx" _
    , Destination:=Worksheets("Sheet1").Range("$A$1"))[/VBA]

    David


  6. #6
    VBAX Contributor
    Joined
    Apr 2012
    Posts
    107
    Location
    Thank you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •