+ Reply to Thread
Results 1 to 14 of 14

getElementsByTagName("table") unable to access table data using IE10

  1. #1
    Registered User
    Join Date
    09-19-2013
    Location
    NZ
    MS-Off Ver
    Excel 2013
    Posts
    9

    getElementsByTagName("table") unable to access table data using IE10

    I am trying to access two tables within a stock data website using IE10, I cannot use the record macro and then add website data as the website being accessed requires a login. I have attempted to access one of the tables using this section of code, site is active and is accessed using InternetExplorer object:
    Please Login or Register  to view this content.
    With no success, the error triggered is: "Object variable or With block variable not set" with the debugger highlighting this line;
    Please Login or Register  to view this content.
    At a guess it is because there are no TDelements named "td", I have tried numerous other names here with no avail.

    The HTML for each table is as follows:
    Table one:
    HTML Code: 
    Table two:
    HTML Code: 
    So my question is how do I access the data table, if it is possible?
    Thank you in advance.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: getElementsByTagName("table") unable to access table data using IE10

    All the TD elements have a tagname of TD, and you are using getElementByTagName, so I don't think that's the problem.

    What could be the problem is declaring TDeleements as an HTMLDTElement then trying to set it as a reference to a collection of TD elements.

    Try declaring as Object instead.

    The could also be a problem with document.

    Can you post the rest of the code?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    09-19-2013
    Location
    NZ
    MS-Off Ver
    Excel 2013
    Posts
    9

    Re: getElementsByTagName("table") unable to access table data using IE10

    Thank you for your quick reply,
    Here is the entire code:
    Please Login or Register  to view this content.
    I included option explicit in the module this time and you are right it is throwing a Compile error: Variable not defined and highlighting TDelement from this line
    Please Login or Register  to view this content.
    I have tried setting both TDelement and TDelements as objects but it still comes up with the same error. Not sure what else I could define them as.

  4. #4
    Registered User
    Join Date
    09-19-2013
    Location
    NZ
    MS-Off Ver
    Excel 2013
    Posts
    9

    Re: getElementsByTagName("table") unable to access table data using IE10

    Firstly thanks again Norie for your guidance.
    Update for users with a similar problem, I couldn't record a marco from the page that I wanted data from for a reason not apparent to myself, so instead I found another page on the site which I could access via the "New Web Queary" box which also included a table. From this I recorded a macro and modified it by editing out the CommandType line and replacing the URL with the one I wanted data from, here is the (edited) macro:
    Please Login or Register  to view this content.
    Although this code doesn't really solve my original question and feels more like a band-aid fix and I would still find the answer very useful so I won't mark this post as solved yet.

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: getElementsByTagName("table") unable to access table data using IE10

    Isn't the instance of Internet Explorer you've created called MyBrowser, not IE?.

  6. #6
    Registered User
    Join Date
    09-19-2013
    Location
    NZ
    MS-Off Ver
    Excel 2013
    Posts
    9

    Re: getElementsByTagName("table") unable to access table data using IE10

    Haha opps, yes you are right. Have changed it, but it is still showing Empty for both TDelement and TDelements in this line
    Please Login or Register  to view this content.
    (which I somehow didn't put into the full macro posted above, goes below c=0)

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: getElementsByTagName("table") unable to access table data using IE10

    I'm not sure getting every TD element from the page is the right approach if you want data from specific table/tables.

    It would probably be better to start of getting the tables you want.

    Then you can loop through there rows and cells(columns) to get the data.

    This is the sort of thing I've used in the past to get the data from a table, it's pretty rough but it works.
    Please Login or Register  to view this content.
    Is there anyway you can identify the table(s) you want?
    Last edited by Norie; 12-04-2013 at 06:35 AM.

  8. #8
    Registered User
    Join Date
    09-19-2013
    Location
    NZ
    MS-Off Ver
    Excel 2013
    Posts
    9

    Re: getElementsByTagName("table") unable to access table data using IE10

    So by the looks that code will post each 'element' of table t into the corresponding cell of sheet1 which is exactly what I want.
    Quote Originally Posted by Norie View Post
    Is there anyway you can identify the table(s) you want?
    No I'm not sure how to identify the table they have no id tags although when I specify 6 for the recorded macro above it gives me both the tables.
    SumStat2.jpgSumStats.PNG
    Those are the two tables I am trying to get with the HTML shown for SumStat2, I can't see any obvious way to reference them unless I can somehow use table.data?

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: getElementsByTagName("table") unable to access table data using IE10

    Is there no way to identify them?

    For example, are they contained within another element, eg a DIV, or even another table.

    Are they the only table with the classname 'data'?

    What happens if you try this code in place of what you had for the TD elements?
    Please Login or Register  to view this content.

    PS You might need to add a few declarations, eg colTbls, T, I etc and change sheet names.
    Last edited by Norie; 12-04-2013 at 06:35 AM.

  10. #10
    Registered User
    Join Date
    09-19-2013
    Location
    NZ
    MS-Off Ver
    Excel 2013
    Posts
    9

    Re: getElementsByTagName("table") unable to access table data using IE10

    Quote Originally Posted by Norie View Post
    Are they the only table with the classname 'data'?
    Yes both have the classname "data" and are the only one's. Is there a way to get a table by class?

  11. #11
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Did you try the last code I posted?

  12. #12
    Registered User
    Join Date
    09-19-2013
    Location
    NZ
    MS-Off Ver
    Excel 2013
    Posts
    9

    Re: getElementsByTagName("table") unable to access table data using IE10

    Oh sorry I didn't read your previous post properly the reason I want to automatically get the tables using vba is because I need to download one for each ticker symbol, of which I have over 100, and the data changes daily. So I want an update button sort of thing.

    I'm just going to make do with the macro I recorded and modified.
    This is the almost finish macro for anyone interested:
    Please Login or Register  to view this content.

  13. #13
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: getElementsByTagName("table") unable to access table data using IE10

    If you are going to use web queries then you shouldn't need the part of the code that automates IE.

  14. #14
    Registered User
    Join Date
    09-19-2013
    Location
    NZ
    MS-Off Ver
    Excel 2013
    Posts
    9

    Re: getElementsByTagName("table") unable to access table data using IE10

    Yes and no, as far as I can tell the web queries function uses an instance of internet explorer so when I login with IE the web query recognizes that the site is already logged in. In other words I don't know how to log into the site using the web query alone.

    Edit: You are right, the web query appears to be completely independent of IE and remembers my login details from when I recorded the macro.
    Last edited by kingnismo; 12-04-2013 at 06:52 PM.

+ 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: 09-23-2013, 02:33 AM
  2. Replies: 2
    Last Post: 06-06-2013, 12:45 PM
  3. [SOLVED] Is there a way to change the error "div/0" in data table to "--" using cond. formatting?
    By Snowpear in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 12-04-2012, 01:05 PM
  4. [SOLVED] How to Count number of "Error" and "OK" after the word "Instrument" found in table row
    By eltonlaw in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-17-2012, 06:26 AM
  5. "Fall down" a VBA created Pivot Table from data Access
    By Radke in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-06-2005, 07:20 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