Custom Function not working in Excel 2013 (64bit)

Lambrix

Board Regular
Joined
Jun 29, 2012
Messages
62
Good morning!

I found a cool custom function (listed below) on the web that pulls the Stock data from Yahoo Finance. It works great in excel 2010 (32bit) but when I run it on my home computer with Excel 2013 (64 bit) the function comes back as '#NAME' and I haven't been able to find solutions on the web for trouble shooting the function.

Any idea what is causing this error?


Code:
    Function StockQuote(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
    StockQuote = 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 price close is the 5th entry
    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(4) ' 4 means: 5th position, starting at index 0

    ' Debug.Print vbLf
    ' Debug.Print strRows(1)
    ' Debug.Print "dbClose: " & dbClose

    StockQuote = dbClose

    Set http = Nothing

    End Function
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
I don't think it's related to 32/64 bit ... it uses an XML reference and if that reference were hard-coded in the code (e.g. add this dll from .... C:\Windows\System32\msxml6.dll) then the path would be dependent on 32/64 bit but it does not. So it seems that only the reference is missing.

If you go tools, references in VBA and add Microsoft XML, v6.0 does it work?
 
Upvote 0
A #NAME error would tend to indicate that either you haven't enabled macros, the code is in the wrong place, or the function call is incorrect.
 
Upvote 0
I don't think it's related to 32/64 bit ... it uses an XML reference and if that reference were hard-coded in the code (e.g. add this dll from .... C:\Windows\System32\msxml6.dll) then the path would be dependent on 32/64 bit but it does not. So it seems that only the reference is missing.

If you go tools, references in VBA and add Microsoft XML, v6.0 does it work?


I added the reference to XML v6.0 and it still doesn't work and I double checked that Macros were enabled in the Trust Center. It's still not working. The excel file literally works on my Excel 2010 32bit version but as soon as I email the document over to my other computer the same function gives the '#NAME' error
 
Upvote 0
I can imagine - it works for me too (64 bit):

Sub StockQuoteTest()
StockQuote ("GSK")
End Sub

What if you step through the code with F8 to see what is causing the error?
 
Upvote 0
I can imagine - it works for me too (64 bit):

Sub StockQuoteTest()
StockQuote ("GSK")
End Sub

What if you step through the code with F8 to see what is causing the error?


Are you using 2013 or 2010 64 bit?

The function does not allow you to step through the code, only with Macros.
 
Upvote 0
64 bit.

You can step through a function as you would with a sub, but only once it has been called. Try stepping through this sub:

Sub StockQuoteTest()
StockQuote ("GSK")
End Sub
 
Upvote 0
Dang! That was it. When I ran the Sub procedure you listed it came back with "Project disabled". I had to enable the macro and then restart the excel sheet and it's working now. Thanks for the assist!
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top