+ Reply to Thread
Results 1 to 12 of 12

WebService error in VBA macro.

  1. #1
    Registered User
    Join Date
    03-13-2017
    Location
    Manchester, England
    MS-Off Ver
    Excel 2013, version 15.0.4903.1002
    Posts
    20

    WebService error in VBA macro.

    Hi, I'm new to this Forum.
    I'm using Excel 2013, Windows 10.

    I'm trying to write a macro (VBA) to use WebService, but it continually errors with: Compile Error Sub or Function not defined.

    I can get WebService to work on a Worksheet, by typing in cell B7 =NUMBERVALUE(WEBSERVICE("http://finance.yahoo.com/d/quotes.csv?s="&A1&",&f=l1&"))

    Here's my simple Macro:

    Sub Quote()

    Sheets("Sheet1").Cells(7, "B") = NumberValue(WebService("http://finance.yahoo.com/d/quotes.csv?s=" & A1&, f = "l1&"))

    End Sub


    In cell A1 I have the stock symbol e.g. DLG.L

    I wish the value defined by l1 (Current Price) to be put in cell B7.

    Please keep your replies simple, as I'm fairly new to this.
    Thank you.

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: WebService error in VBA macro.

    Hi,

    You cannot simply type formulas into VBA code, I'm afraid. You might enter the formula into the cell and then replace with its value if required
    Please Login or Register  to view this content.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  3. #3
    Registered User
    Join Date
    03-13-2017
    Location
    Manchester, England
    MS-Off Ver
    Excel 2013, version 15.0.4903.1002
    Posts
    20

    Re: WebService error in VBA macro.

    Thanks for your reply.

    Yes, it now doesn't give a compile error. I can see that the formula is now defined.
    However, copying your solution into my Macro, doesn't give any result in cell B7.

  4. #4
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: WebService error in VBA macro.

    If you remove the .Value = .Value line, do you see a result?

  5. #5
    Registered User
    Join Date
    03-13-2017
    Location
    Manchester, England
    MS-Off Ver
    Excel 2013, version 15.0.4903.1002
    Posts
    20

    Re: WebService error in VBA macro.

    Hi

    Whether the line Value = .Value is there or not, cell B7 gives the result value of zero (0)

  6. #6
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: WebService error in VBA macro.

    Does the formula in there look correct?

  7. #7
    Registered User
    Join Date
    03-13-2017
    Location
    Manchester, England
    MS-Off Ver
    Excel 2013, version 15.0.4903.1002
    Posts
    20

    Re: WebService error in VBA macro.

    Hi

    It'll probably help if I tell you what I've done so far.

    When I entered your suggestion (exactly) I got a compile error, so I removed the period before Formula and Value.
    That gave no compile errors. But I now see that was not correct.

    The (new) compile error is: Application defined or Object defined error. The line .Formula is hi-lited in yellow

  8. #8
    Registered User
    Join Date
    03-13-2017
    Location
    Manchester, England
    MS-Off Ver
    Excel 2013, version 15.0.4903.1002
    Posts
    20

    Re: WebService error in VBA macro.

    Sorry, it's a run-time error 1004

  9. #9
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: WebService error in VBA macro.

    Aha- there is a difference between the original formula and the formula version in your original code, and I copied the latter. Try this
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    03-13-2017
    Location
    Manchester, England
    MS-Off Ver
    Excel 2013, version 15.0.4903.1002
    Posts
    20

    Re: WebService error in VBA macro.

    Hi xlnitwit

    Yes that works lovely. Thank you very much.
    Just so I understand, and therefore become slightly more educated in Excel VBA.
    What is the significance of double quotes rather than single quotes.

  11. #11
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: WebService error in VBA macro.

    The double quotes are necessary to escape the single ones inside a quoted string.

    The syntax for putting a formula in a cell is
    Please Login or Register  to view this content.
    and the compiler treats everything inside pairs of quotes- the two highlighted quotes- as the string. If the string in between the quotes itself contains quotes, the compiler would treat each pair as separate strings. In the case of your formula, that would look like this
    Please Login or Register  to view this content.
    so the compiler would see three strings, and some supposed VBA commands which would make no sense to it in terms of VBA syntax.

    By doubling up the quotes inside the string, the compiler knows not to treat them as terminating the original string
    Please Login or Register  to view this content.
    Does my explanation make sense to you?

  12. #12
    Registered User
    Join Date
    03-13-2017
    Location
    Manchester, England
    MS-Off Ver
    Excel 2013, version 15.0.4903.1002
    Posts
    20

    Re: WebService error in VBA macro.

    Thanks xlnitwit,
    Yes your explanation makes perfect sense.

    Thank you for persevering with me and solving my problem.
    All the best
    Excelerate1

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Calling Webservice: Error (Index was outside the bounds of the array)
    By NeedForExcel in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-08-2015, 12:45 AM
  2. Using WebService with Yahoo API
    By Jeremy35 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 03-09-2015, 01:36 PM
  3. Consuming a WebService using VBA [Help !]
    By Aeon in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-04-2014, 05:31 AM
  4. "Object not set" error - calling a webservice from excel 2007
    By bnath001 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-04-2009, 10:20 AM
  5. [SOLVED] Excel 2003: Grabbing a dataset from a webservice and then sending to a webservice?
    By gjn in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-07-2005, 11:05 AM
  6. [SOLVED] ASP.NET Vb calling webservice
    By Larry in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-16-2005, 01:06 AM
  7. [SOLVED] xml webservice Client
    By Ven in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-06-2005, 01:06 AM

Tags for this Thread

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