how to get table data using macro . RRS feed

  • Question

  • Sub Macro11()
    ' Macro1 Macro
    Dim IE As Object
    Dim tbls, tbl, trs, tr, tds, td, r, c
       Set IE = CreateObject("InternetExplorer.application")
        IE.Visible = True
        IE.navigate ("https://www.facebook.com/?id=" & ActiveCell)
            If IE.ReadyState = 4 Then
                IE.Visible = True
                Exit Do
            End If
        IE.Document.forms(0).all("username").Value = "user"
        IE.Document.forms(0).all("password").Value = "mobi"
    '   ie.Navigate (";https://datatables.net/examples/basic_init/alt_pagination.html)
    Application.Wait Now + TimeSerial(0, 0, 4)
        Set tbls = IE.Document.getElementsByTagName("table")
        For r = 0 To tbls.Length - 1
            Debug.Print r, tbls(r).Rows.Length
        Next r
        Set tbl = IE.Document.getElementsByTagName("table")(5)
        Set trs = tbl.getElementsByTagName("tr")
        For r = 0 To trs.Length - 1
            Set tds = trs(r).getElementsByTagName("td")
            'if no <td> then look for <th>
            If tds.Length = 0 Then Set tds = trs(r).getElementsByTagName("th")
            For c = 0 To tds.Length - 1
                ActiveSheet.Range("B4").Offset(r, c).Value = tds(c).innerText
            Next c
        Next r
    End Sub
    i am using this but unable to fetch data. i want to first logon to the webpage then open new page want to fetch html table data. how to do this ?


    Friday, June 26, 2015 7:47 AM

All replies

  • Firstly, you should define data-type.
    .... "Dim tbls, tbl, trs, tr, tds, td, r, c" ... what are they?
    Friday, June 26, 2015 9:37 AM
  • Your question has absolutely nothing to do with Microsoft Word, the topic of the forum in which you posted. You're certainly not going to get a useful answer in that venue, so I'm moving your question for re-routing.

    Cindy Meister, VSTO/Word MVP, my blog

    Friday, June 26, 2015 3:41 PM
  • Here's some sample code of how to login to a website.


    How about you get the login pare working, and post back. 

    I looked at the link in your code.  It doesn't seem to do a whole lot, as far as I can tell, but maybe that's because I wasn't logged in.

    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

    Saturday, June 27, 2015 3:48 AM
  • i have declared these data-type at the top.


    Monday, June 29, 2015 4:51 AM
  • ryguy72 using this code i have login in any website to enter username and password.

    you can use this code to enter your any social media account using your username and password. 

    i heave login in webpage successfully but i am unable to fetch table data in excel sheet. Now just i want to fetch whole table data only.


    Monday, June 29, 2015 4:55 AM
  • you can put your own username and password of fb in my code.then you would log in .first 14 lines of my code is to login in the website. and its 100% working. i am not able to get data from table. help me if you can get..


    Monday, June 29, 2015 5:14 AM