Results 1 to 20 of 20

Problem with VBA statement http.send

Threaded View

  1. #1
    Registered User
    Join Date
    01-20-2013
    Location
    Massachusetts, USA
    MS-Off Ver
    Excel 2003
    Posts
    48

    Problem with VBA statement http.send

    I have been successfully running a VBA macro for several years that retrieves data from a website at http://ichart.finance.yahoo.com

    It fetches data from that website with a formula "=StockCloseAdj(stock symbol, date)" and populates return info into the cell in my EXCEL spreadsheet.

    About 1-2 weeks ago it stopped working and returns the argument as #VALUE!

    I have attached a text version of the macro.

    I tried manually debugging the code.

    It appears to execute the line:
    http.Open "GET", strURL, False

    But crashes when it gets to:
    http:send

    This macro has been extremely valuable to me because I can use it to access the daily "Adj. Close" price for as many stocks as I want going back as many years as I want.

    I'm not good at debugging, so it's possible that something other than the line I indicated above is causing the problem.

    Can anyone help?

    I'll also post in the macro text below in case their is a problem with my attachment:

    Metsci

    = = = = = = = = = = = = = = = = = = = = = = =
    Function StockCloseAdj(strTicker As String, Optional dtDate As Variant)
    ' Date is optional - if omitted, use today. If value is not a date, throw error.
        If IsMissing(dtDate) Then
            dtDate = Date
        Else
            If Not (IsDate(dtDate)) Then
            StockCloseAdj = CVErr(xlErrNum)
            End If
        End If
    
        Dim dtPrevDate As Date
        Dim strURL As String, strCSV As String, strRows() As String, strColumns() As String
        Dim dbClose As Double
    
        dtPrevDate = dtDate - 7
    
    ' Compile the request URL with start date and end date
        strURL = "http://ichart.finance.yahoo.com/table.csv?s=" & strTicker & _
            "&a=" & Month(dtPrevDate) - 1 & _
            "&b=" & Day(dtPrevDate) & _
            "&c=" & Year(dtPrevDate) & _
            "&d=" & Month(dtDate) - 1 & _
            "&e=" & Day(dtDate) & _
            "&f=" & Year(dtDate) & _
            "&g=d&ignore=.csv"
    
    ' Debug.Print strURL
    
        Set http = CreateObject("MSXML2.XMLHTTP")
        http.Open "GET", strURL, False
        http.Send
        strCSV = http.responseText
    
    ' Debug.Print strCSV
    
    ' The most recent information is in row 2, just below the table headings.
    ' The   ? ? ? ?         is the 1st entry    index = 0
    ' The   open price      is the 2nd entry    index = 1
    ' The   high price      is the 3rd entry    index = 2
    ' The   low  price      is the 4th entry    index = 3
    ' The   price close     is the 5th entry    index = 4
    ' The   volume          is the 6th entry    index = 5
    ' The   adjusted close  is the 7th entry    index = 6
        strRows() = Split(strCSV, Chr(10)) ' split the CSV into rows
        strColumns = Split(strRows(1), ",") ' split the relevant row into columns. 1 means 2nd row, starting at index 0
        dbClose = strColumns(6) ' 6 means: 7th position, starting at index 0
    
    ' Debug.Print vbLf
    ' Debug.Print strRows(1)
    ' Debug.Print "dbClose: " & dbClose
    
        StockCloseAdj = dbClose
    
    Set http = Nothing
    
    End Function
    Attached Files Attached Files
    Last edited by alansidman; 05-19-2017 at 09:06 AM. Reason: code tags added

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Unable to send mails problem
    By mso3 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-22-2015, 09:32 PM
  2. Problem with userform before send
    By johncassell in forum Outlook Programming / VBA / Macros
    Replies: 1
    Last Post: 06-01-2015, 03:59 PM
  3. Send Email If statement
    By Toyo613 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-30-2014, 02:28 PM
  4. Replies: 8
    Last Post: 01-30-2014, 03:12 PM
  5. IE send key function problem
    By ckjason in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 08-31-2012, 11:23 AM
  6. [SOLVED] CDO send mail problem
    By Piotr in forum Excel General
    Replies: 5
    Last Post: 12-21-2005, 09:40 AM
  7. Send Button Problem
    By Meister in forum Excel General
    Replies: 0
    Last Post: 09-27-2005, 06:05 AM

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