1

I use a webservice function to get commodity prices in an Excel spreadsheet. I have VBA code that references the values of the cells in which these prices are stored. I would like to be able to get this value stored in my macro without having to use the function in a cell. An example of my webservice function:

=WEBSERVICE("http://finance.yahoo.com/d/quotes.csv?s=CLF16.nym&f=l1")

My macro takes the current month and year to build the URL (the ticker codes for futures vary by date, so CLF16.nym is crude oil price for January 2016).

Is it possible to get this commodity price as a value in VBA without using the webservice function?

2
  • 1
    Do you simply want to avoid using functions directly on the worksheet, or is there something about this particular function you want to avoid? Commented Oct 29, 2015 at 14:29
  • I'm trying to avoid using functions directly on the worksheet. Commented Oct 29, 2015 at 14:33

1 Answer 1

1

Since you just want to avoid using the function on the sheet, you can use the very same worksheet formula directly in code by using the WorksheetFunction property of Application, e.g.:

Dim s As String
s = Application.WorksheetFunction.WebService("http://finance.yahoo.com/d/quotes.csv?s=CLF16.nym&f=l1")
Sign up to request clarification or add additional context in comments.

1 Comment

Simple enough. When starting out in VBA I always had problems using worksheet functions in VBA and abandoned that technique. Seems to work fine though!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.