+ Reply to Thread
Results 1 to 4 of 4

Applying a formula to Get From Web URL with VBA Macro

  1. #1
    Registered User
    Join Date
    09-25-2012
    Location
    colorado
    MS-Off Ver
    Excel 2007
    Posts
    5

    Applying a formula to Get From Web URL with VBA Macro

    I'm trying to find a way to apply a formula to a get data from web url.

    So the url will look like:

    http://www.thisurl.com/formula/restOfTheUrl

    I'm new to this, so I tried recording the macro using the Advanced Get From Web function and breaking out the elements of the URL from there and substituting the formula in.

    So the section of the code looked like this

    Please Login or Register  to view this content.
    If the code worked as expected, the url output would've been:

    http://www.thisurl.com/6/restOfTheUrl

    The error I'm getting is:

    Run-time error '1004': Application-defined or object-defined error

    I'm using the sum formula just for proof of concept & testing purposes.

    The beginning of the macro that was recorded that leads into the formula-URL issue is:

    Please Login or Register  to view this content.
    I found this question being asked which is similar to what I am asking, but it is from 2002 and their answer doesn't line up with the output I'm seeing from the recorded macro.

    https://www.mrexcel.com/forum/excel-questions/11732-perform-web-query-url-cell.html

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,863

    Re: Applying a formula to Get From Web URL with VBA Macro

    I can see 2 problems:
    obvious one - sum in VBA
    more complicated - double quotes. probably web contents expects string enclosed in double quotes. so to start such string you need 3 doublequotes - first is just "this will be string" signal, next 2 will be interpreted as one doublequote
    Try:
    Please Login or Register  to view this content.
    or
    Please Login or Register  to view this content.
    Last edited by Kaper; 10-24-2017 at 05:26 PM.
    Best Regards,

    Kaper

  3. #3
    Registered User
    Join Date
    09-25-2012
    Location
    colorado
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Applying a formula to Get From Web URL with VBA Macro

    Appreciate the response!

    At the moment, I don't think this is the solution, so let me give some more details here. Part of the problemI think is definitely quotation mark usage since the URL I'm working with contains quotation marks.

    First, I recorded a macro using Get Data From Web and the Basic option.

    The URL I used was basically: http://www.thisurl.com/abc/subject=["word1","word2"]&output=xml

    Recorded Marco Output:

    Please Login or Register  to view this content.
    This macro will work and give me the output I need.

    Then I tried recording the Get Data From Web and with the Advanced option breaking the URL up into 3 parameters.

    Param1: http://www.thisurl.com/abc/subject=["
    Param2: word1
    Param3: "]&output=xml

    Recorded Macro Output:

    Please Login or Register  to view this content.
    This macro works so long as ""word1"" is a static string of text between two quotation marks.

    I just tried subbing ""word1"" with application.Sum(1,2,3) and got the same error.

    The end goal here is to be able to control what goes in the third parameter based on other data. I already have a function set up that should do that. Right now I'm just trying to find a way to run any function in the middle of a URL if that is possible.

  4. #4
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,863

    Re: Applying a formula to Get From Web URL with VBA Macro

    I'm not sure if you got my message about playing with doublequotes. I'm almost sure the issue is here. May be - after carefull reading of your code from post #3 I could recommend such experiment:
    Please Login or Register  to view this content.
    so the last doublequote here:
    "let" & Chr(13) & "" & Chr(10) & "blabla(""http://www.blabla=["""""" & """ finishes the string then & concatenates it with result of application.sum (converted on the fly to string type*) then again & concatenates with next string so we have to start this string with doublequote """ & """"""]&blabla"")),"

    *one could force this conversion like
    Please Login or Register  to view this content.
    but it is not necessary.
    Last edited by Kaper; 10-27-2017 at 04:31 PM. Reason: added explanation with red doublequotes

+ 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. Macro help applying formula to dynamic number of rows for different files (s/b EASY)
    By yankeekid86 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-20-2014, 04:38 PM
  2. Help with applying this macro to the whole workbook
    By Sagaroth in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-09-2013, 07:07 AM
  3. [SOLVED] Applying Macro across several worksheets
    By daniel_t in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-31-2012, 02:08 PM
  4. Macro: Applying formula to multiple cells in excel (formula editing)
    By city in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-27-2012, 06:41 AM
  5. applying formula and formatting to group of cells in a macro
    By vmd0957 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-24-2008, 04:53 PM
  6. Applying macro within a custom macro button to all workbooks
    By clearwaterdave in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-16-2007, 12:16 PM
  7. Applying macro within a custom macro button to all workbooks
    By BigBas in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-14-2007, 03:34 PM
  8. [SOLVED] Applying Macro to only certain sheets
    By Darin Kramer in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-13-2005, 01:05 PM

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