+ Reply to Thread
Results 1 to 23 of 23

VBA to extract data from web [javascropt]

  1. #1
    Registered User
    Join Date
    10-19-2016
    Location
    Dhaka
    MS-Off Ver
    2013
    Posts
    54

    VBA to extract data from web [javascropt]

    Hello Friends,

    I am here to get your help. I have tried to extract data by web-query from a website which provide daily stock data for our local market. But I failed.
    I think the web source code is programmed with javasript. I cant get desired table data by web query. I am not expert in VBA, so I seek your help.
    I am attaching a screenshot here. I wish to browse / view the data same in my excel workbook.

    If you select any stock from the list, it will show you the stocks current ask and bid price in a table manner. And also display today summery of selected stock.

    Any kind of help appreciate me.
    Thanks in Advance.

    N.B: The table fully viewed while market remain open @ GMT 4:30 - 8:30 | Sunday - Thursday.
    Last edited by iqbal.88; 12-20-2017 at 06:59 AM.

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: VBA to extract data from web [javascropt]

    Looks pretty easy to pick up, using Power Query. The javascript on the listbox simply passes the instrument string as an argument to a php page, which is then returned. That php page has 3 tables (Buy, Sell and Price) which you can then easily import and transform.

    What does your required output look like?

    Here's an example of how to get the price table, for a given instrument:

    Please Login or Register  to view this content.
    Can you tweak that to suit your requirement? Ask for more help, if needed.
    Last edited by Olly; 12-15-2017 at 09:50 AM.
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: VBA to extract data from web [javascropt]

    Here's an example of how you may want to use it - this has a query to retrieve all the instrument codes, and use them as a data validation source, in a list. When an instrument is selected, the queries refresh, to update the Price, Buy and Sell tables.

    Helpful?
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    10-19-2016
    Location
    Dhaka
    MS-Off Ver
    2013
    Posts
    54

    Re: VBA to extract data from web [javascropt]

    Dear Olly, thanks brother for your quick response. Its my late reply I was outside from home.
    Ok, Your solution little confusion me. Actually I am not familiar with power query, is it an extra tool for data query?

    Basically, I want to view/browse multiple instruments data in single excel sheet. if the solution for one instrument done by VBA with auto refresh , then I should edit it for multiple scenario.
    Last edited by iqbal.88; 12-16-2017 at 06:42 AM.

  5. #5
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: VBA to extract data from web [javascropt]

    Did you try my attached workbook?

    See this link for clear instructions on how to install Power Query in Excel 2013: https://www.excelcampus.com/install-power-query/

  6. #6
    Registered User
    Join Date
    10-19-2016
    Location
    Dhaka
    MS-Off Ver
    2013
    Posts
    54

    Re: VBA to extract data from web [javascropt]

    Quote Originally Posted by Olly View Post
    Here's an example of how you may want to use it - this has a query to retrieve all the instrument codes, and use them as a data validation source, in a list. When an instrument is selected, the queries refresh, to update the Price, Buy and Sell tables.

    Helpful?

    Thanks Brother, Its look like what I wish for. But its not work for me
    Last edited by iqbal.88; 12-15-2017 at 12:41 PM. Reason: missing text

  7. #7
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: VBA to extract data from web [javascropt]

    Quote Originally Posted by iqbal.88 View Post
    Thanks Brother, Its look like what I for. But its not work for me
    Have you installed the Power Query Add-In?

  8. #8
    Registered User
    Join Date
    10-19-2016
    Location
    Dhaka
    MS-Off Ver
    2013
    Posts
    54

    Re: VBA to extract data from web [javascropt]

    Power Query Installation showing Error for me

    Update: I managed to install Power Query.

    But it sowing some error message, when select instrument from drop down list. After sometimes it goes blank in result, No value in dropdown box.
    Last edited by iqbal.88; 12-15-2017 at 01:39 PM.

  9. #9
    Registered User
    Join Date
    10-19-2016
    Location
    Dhaka
    MS-Off Ver
    2013
    Posts
    54

    Re: VBA to extract data from web [javascropt]

    Brother its a sad for me, till I am failed to test your idea also power query not make me a sense.

  10. #10
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: VBA to extract data from web [javascropt]

    What is the error message?

  11. #11
    Registered User
    Join Date
    10-19-2016
    Location
    Dhaka
    MS-Off Ver
    2013
    Posts
    54

    Re: VBA to extract data from web [javascropt]

    Hello Brother,

    1. After a change in dropdown list Excel sheet be non responsive. Seems to be hang. After a while it gone blank in dropdown list (no value in dropdown list).
    2. [Expression.Error] we can not convert value null to text.

  12. #12
    Registered User
    Join Date
    10-19-2016
    Location
    Dhaka
    MS-Off Ver
    2013
    Posts
    54

    Re: VBA to extract data from web [javascropt]

    is it possible to fix the issue in macro ??

  13. #13
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: VBA to extract data from web [javascropt]

    The problem isn't in the VBA code - all that is doing is triggering the query to refresh, when you change the instrument code in cell E2.
    It seems that no web page is being returned for the selected instrument. However, I can't recreate your error...

    Which instrument code did you select? Try opening a browser and visiting http://www.dsebd.org/bshis_new1_old.php?w=XXXX - replace XXX with the instrument code you tried. Does the page open ok?

  14. #14
    Registered User
    Join Date
    10-19-2016
    Location
    Dhaka
    MS-Off Ver
    2013
    Posts
    54

    Re: VBA to extract data from web [javascropt]

    Brother Please Look the Following Screenshots

    PQ_test4.png

    PQ_Error.PNG

  15. #15
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: VBA to extract data from web [javascropt]

    Please try what I asked you in post #13.

  16. #16
    Registered User
    Join Date
    10-19-2016
    Location
    Dhaka
    MS-Off Ver
    2013
    Posts
    54

    Re: VBA to extract data from web [javascropt]

    Quote Originally Posted by Olly View Post
    Please try what I asked you in post #13.
    Yes the page open in browser, OK.
    look in screenshot drop-down list is BLANK, and then the error message

  17. #17
    Registered User
    Join Date
    10-19-2016
    Location
    Dhaka
    MS-Off Ver
    2013
    Posts
    54

    Re: VBA to extract data from web [javascropt]

    Dear Olly Brother, It works for me. I just restored my windows OS & re-install MS office 2013 with latest updates.
    Now power query solution works, but with my limitation. Thank You

    Question:
    H5:H14 and K5:K14, these range value not work in another function Like, Sum or Average
    How could I call this range value to another function in different cell??

  18. #18
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: VBA to extract data from web [javascropt]

    Quote Originally Posted by iqbal.88 View Post
    Question:
    H5:H14 and K5:K14, these range value not work in another function Like, Sum or Average
    How could I call this range value to another function in different cell??
    What are you trying to do?

    Also, which Instrument is returning data for Buy / Sell?

  19. #19
    Registered User
    Join Date
    10-19-2016
    Location
    Dhaka
    MS-Off Ver
    2013
    Posts
    54

    Re: VBA to extract data from web [javascropt]

    Like, I want to calculate Total, & Average of buy/sell volume in different cell and count if the cell have value within range. For each instrument which is selected in drop-down cell.

    Each instrument return data which has data in website.
    Last edited by iqbal.88; 12-19-2017 at 10:43 AM.

  20. #20
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: VBA to extract data from web [javascropt]

    Select the table, click TableTools | Design > Table Style Options > check "Total Row"


    Can you answer my question about which instrument is returning Buy / Sell data? They all seem blank to me.

  21. #21
    Registered User
    Join Date
    10-19-2016
    Location
    Dhaka
    MS-Off Ver
    2013
    Posts
    54

    Re: VBA to extract data from web [javascropt]

    Quote Originally Posted by Olly View Post
    Can you answer my question about which instrument is returning Buy / Sell data? They all seem blank to me.
    Brother, Buy/Sell data is realtime. It returns only when market is open.
    I already mention it in the bottom of my very first post. Quoted from the post
    "N.B: The table fully viewed while market remain open @ GMT 4:30 - 8:30 | Sunday - Thursday."

    In addition, I need to analyse / calculate some parameter based on buy/sell data. I need to reference table range or specific cell value to another formula.
    Last edited by iqbal.88; 12-19-2017 at 11:50 AM.

  22. #22
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: VBA to extract data from web [javascropt]

    Quote Originally Posted by iqbal.88 View Post
    In addition, I need to analyse / calculate some parameter based on buy/sell data. I need to reference table range or specific cell value to another formula.
    It's easy to do that - the tables returned are just normal listobject tables, which you can reference like any other.

    I think this thread is now closed - it's answered your question, as far as I can see. If you have other questions about formulas to analyse the data returned, that's a different requirement. I suggest you mark this thread SOLVED (please select Thread Tools from the menu link above and mark this thread as SOLVED).

    Thanks.

  23. #23
    Registered User
    Join Date
    10-19-2016
    Location
    Dhaka
    MS-Off Ver
    2013
    Posts
    54

    Re: VBA to extract data from web [javascropt]

    Brother, it should be easy as per I think. But Why not my formula work in your sheet?? I have tried, but it returns only 0 in result :/
    Please take a look in sheet. I will close this thread after your reply in this issue. Please

    Ref Error.PNG

+ 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. Replies: 2
    Last Post: 10-18-2017, 02:12 PM
  2. [SOLVED] vba code to extract data from data table and update data sheet
    By JEAN1972 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-25-2017, 01:23 PM
  3. [SOLVED] Extract Data /Look up Data / To get data automatically by refering invoice number
    By PMH2384 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 04-17-2017, 04:03 AM
  4. Replies: 1
    Last Post: 06-09-2016, 12:12 PM
  5. Replies: 3
    Last Post: 12-18-2014, 10:27 AM
  6. Extract all data to new workbook then filter and extract to new worksheets
    By graphicgoose in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-04-2014, 08:18 PM
  7. Replies: 11
    Last Post: 12-04-2012, 02:56 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