+ Reply to Thread
Results 1 to 2 of 2

Downloading Data From Yahoo

Hybrid View

  1. #1
    Registered User
    Join Date
    12-04-2008
    Location
    chicago
    Posts
    11

    Downloading Data From Yahoo

    I have this code below and I "think" it is right but when I execute it I get 1004 application defined or object defined error. This is the FIRST time I am trying to do this, so I am not sure if I need to set something up in EXCEL first.

    Sub GetSub()
    Dim Stock As String
    
        Stock = InputBox("Input Stock")
    
    
    Worksheets("Data").Columns("a:g").ClearContents
    
    
    With Worksheets("Data").Range("h1").QueryTable
        .Connection = _
        "URL;http://ichart.yahoo.com/table.csv?s=" & Stock & "&d=" & Month(Date) - 1 & "&e=" & Day(Date) & "&f=" & Year(Date) & "&g=d&a=0&b=2&c=" & Year(Date) - 4 & "&ignore=.csv"
        .WebSelectionType = xlAllTables
        .WebFormatting = xlWebFormattingNone
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .Refresh BackgroundQuery:=False
    End With
    
    Worksheets("Data").Columns("A:A").TextToColumns Destination:=Worksheets("Data").Range("A1"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
        Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
        :=Array(Array(1, 4), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), _
        Array(7, 1))
        
        
    End Sub

  2. #2
    Registered User
    Join Date
    10-04-2008
    Location
    uk
    Posts
    26
    Hi

    I think this will do what you want


    Sub GetSub()
    
    Dim Stock As String
    
    Stock = InputBox("Input Stock")
    
    Worksheets("Data").Columns("a:g").ClearContents
    
    Dim QT As QueryTable
    Dim strcon As String
    
    strcon = "URL;http://ichart.yahoo.com/table.csv?s=" & Stock & "&d=" & Month(Date) - 1 & "&e=" & Day(Date) & "&f=" & Year(Date) & "&g=d&a=0&b=2&c=" & Year(Date) - 4 & "&ignore=.csv"
    
    Set QT = Worksheets("Data").QueryTables.Add(Connection:=strcon, Destination:=Sheets("Data").Range("A1"))
    
    With QT
        .WebSelectionType = xlAllTables
        .WebFormatting = xlWebFormattingNone
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .Refresh BackgroundQuery:=False
    End With
    
    Worksheets("Data").Columns("A:A").TextToColumns Destination:=Worksheets("Data").Range("A1"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
        Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
        :=Array(Array(1, 4), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), _
        Array(7, 1))
        
        
    End Sub

    qff

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1