+ Reply to Thread
Results 1 to 21 of 21

How can I get the table from this web page?

  1. #1
    Forum Contributor
    Join Date
    11-12-2010
    Location
    HK
    MS-Off Ver
    Excel 2010
    Posts
    189

    How can I get the table from this web page?

    Hi all,

    I have a task to download a table from this web page (http://sdinotice.hkex.com.hk/di/NSAl...=MAIN&lang=EN&). I know the html code for the table should be something like
    (<table cellspacing="0" cellpadding="0" align="Center" rules="all" border="1" id="grdPaging" style="width:970px;border-collapse:collapse;">
    <tr class="boldtxtw" valign="top" style="background-color:#999999;">
    <td>Name of substantial shareholder / director / chief executive</td><td>Reason for disclosure </td><td>No. of shares bought / sold / involved</td><td>Average price per share</td><td>No. of shares interested (See *Notes above)</td><td>% of issued share capital</td><td>Date of relevant event (dd/mm/yyyy)</td><td>Interests in shares of associated corporation</td><td>Interests in debentures</td>)

    As there are several "table" in the whole html code, I would like to use getelementsbytagname("table") first and then look for id by searching getelementbyid("grdPaging") to download the table only. But I don't know how to write this command in vba code. Could anyone shows me a direction please? Thanks in advance.

  2. #2
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: How can I get the table from this web page?

    Hi,

    Since the id of an html element should be unique, so you can directly using getElementById() function.

    You can try this code :

    Please Login or Register  to view this content.
    1. I care dog
    2. I am a loop maniac
    3. Forum rules link : Click here
    3.33. Don't forget to mark the thread as solved, this is important

  3. #3
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Try this !


    Hi,

    if you need to copy the Web table to a worksheet, paste this code directly in a worksheet module :

    Please Login or Register  to view this content.
    Do you like ? So thanks to click on bottom left star « Add Reputation » !
    Last edited by Marc L; 10-09-2014 at 09:56 AM.

  4. #4
    Forum Contributor
    Join Date
    11-12-2010
    Location
    HK
    MS-Off Ver
    Excel 2010
    Posts
    189

    Re: How can I get the table from this web page?

    Thanks a lot Karedog, but is it possible to have a table format like the one shown on the webpage at excel?

    Quote Originally Posted by karedog View Post
    Hi,

    Since the id of an html element should be unique, so you can directly using getElementById() function.

    You can try this code :

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    11-12-2010
    Location
    HK
    MS-Off Ver
    Excel 2010
    Posts
    189

    Re: How can I get the table from this web page?

    Thanks a lot Karedog, but is it possible to have a table format like the one shown on the webpage at excel?

    Quote Originally Posted by karedog View Post
    Hi,

    Since the id of an html element should be unique, so you can directly using getElementById() function.

    You can try this code :

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    11-12-2010
    Location
    HK
    MS-Off Ver
    Excel 2010
    Posts
    189

    Re: Try this !

    Thanks Marc L, but I cannot run the code. Do I need to do any settings on excel in order to run it?

    Quote Originally Posted by Marc L View Post

    Hi,

    if you need to copy the Web table to a worksheet, paste this code directly in a worksheet module :

    Please Login or Register  to view this content.
    Do you like ? So thanks to click on bottom left star « Add Reputation » !

  7. #7
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: How can I get the table from this web page?


    Works like a breeze on my side on several computers with differents Excel & Windows versions !

    If you can run karedog's code, you can run mine !

  8. #8
    Forum Contributor
    Join Date
    11-12-2010
    Location
    HK
    MS-Off Ver
    Excel 2010
    Posts
    189

    Re: How can I get the table from this web page?

    Hi Marc L,

    seem error comes in this code (Me.Paste [C1]: .ParentWindow.clipboardData.clearData "Text")

    Quote Originally Posted by Marc L View Post

    Works like a breeze on my side on several computers with differents Excel & Windows versions !

    If you can run karedog's code, you can run mine !

  9. #9
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: How can I get the table from this web page?


    Did you ever follow my direction before the code ?! Where did you paste it ?!

  10. #10
    Forum Contributor
    Join Date
    11-12-2010
    Location
    HK
    MS-Off Ver
    Excel 2010
    Posts
    189

    Re: How can I get the table from this web page?

    Oops.... I made a mistake to paste in a wrong place. It works now. Thank you so much
    Quote Originally Posted by Marc L View Post

    Did you ever follow my direction before the code ?! Where did you paste it ?!

  11. #11
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: How can I get the table from this web page?

    Quote Originally Posted by lubbamkt View Post
    Thanks a lot Karedog, but is it possible to have a table format like the one shown on the webpage at excel?
    Hi, sorry for the late. Thanks for the reputation point.

    I see that Mark's code have already served you well, but in case you need Internet Explorer object for the solution (IE object has GUI and can be shown if needed, but slower than Mark's code that is using XML object), here is the code :

    Please Login or Register  to view this content.

  12. #12
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: How can I get the table from this web page?


    karetog, faster by pasting the table's outerHTML code in a HTMLFile object
    and reading its elements like in your code from this object … Piloting IE is the slowest !

  13. #13
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: How can I get the table from this web page?

    Quote Originally Posted by Marc L View Post

    karetog, faster by pasting the table's outerHTML code in a HTMLFile object
    and reading its elements like in your code from this object … Piloting IE is the slowest !
    Hi Marc,

    Thanks for the suggestion. I thought it will be ok to wait 2 to 3 seconds more for T.S., since I see there is no need to hurry in this case. I choose IE object because it's visually easy to track in case a problem occured, also can visually observed if we are to put some values to html's form.
    Thanks again for your information.

  14. #14
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: How can I get the table from this web page?


    My suggestion was pasting table code from IE to an HTMLFile object, faster than processing only in IE …

  15. #15
    Forum Contributor
    Join Date
    11-12-2010
    Location
    HK
    MS-Off Ver
    Excel 2010
    Posts
    189

    Re: How can I get the table from this web page?

    Hi Karedog, can I set the URL as a variant since the link I gave in the example was a searched result that varies depending on the search target? Thanks

    Quote Originally Posted by karedog View Post
    Hi, sorry for the late. Thanks for the reputation point.

    I see that Mark's code have already served you well, but in case you need Internet Explorer object for the solution (IE object has GUI and can be shown if needed, but slower than Mark's code that is using XML object), here is the code :

    Please Login or Register  to view this content.

  16. #16
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: How can I get the table from this web page?

    Quote Originally Posted by lubbamkt View Post
    Hi Karedog, can I set the URL as a variant since the link I gave in the example was a searched result that varies depending on the search target? Thanks
    Hi lubbamkt,
    Sure you can, just don't forget to put the variable name in Dim statement, since the code is marked as Option Explicit. You also can show the IE window during the process so you know how it progessing.

    Please Login or Register  to view this content.

  17. #17
    Forum Contributor
    Join Date
    11-12-2010
    Location
    HK
    MS-Off Ver
    Excel 2010
    Posts
    189

    Re: Try this !

    Hi Marc L, I got a Run-time error 429, ActiveX component can't create object in using your code in my home pc which is operating windows 8.1 and MS Office 2010 (32 bit). But the code works well in another pc with windows xp and MS Office 2010 (32 bit).

    Quote Originally Posted by Marc L View Post

    Hi,

    if you need to copy the Web table to a worksheet, paste this code directly in a worksheet module :

    Please Login or Register  to view this content.
    Do you like ? So thanks to click on bottom left star « Add Reputation » !

  18. #18
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: How can I get the table from this web page?


    Depends on which line error occurs !

    Seems something is missing on that computer or maybe administrator mode is required, no permissions allowed …

  19. #19
    Forum Contributor
    Join Date
    11-12-2010
    Location
    HK
    MS-Off Ver
    Excel 2010
    Posts
    189

    Re: How can I get the table from this web page?

    Hi Karedog, May I know how could I remain the hyperlink rather than text in the table, for example in the column of "reason for disclosure"? Many thanks

    Quote Originally Posted by karedog View Post
    Hi lubbamkt,
    Sure you can, just don't forget to put the variable name in Dim statement, since the code is marked as Option Explicit. You also can show the IE window during the process so you know how it progessing.

    Please Login or Register  to view this content.

  20. #20
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: How can I get the table from this web page?


    Example in this thread

  21. #21
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: How can I get the table from this web page?

    Hi,

    If you hover your mouse above column of "reason for disclosure" on the webpage, you will find that this is a javascript code, not a direct link, and since Excel doesn't have javascript engine, you won't able to follow the link. You must do it in your browser. However, you can do this for the "Date of relevant event" column since this is a direct link.

    Please Login or Register  to view this content.

+ 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. Paste values from table on one page to table on another page
    By jamesbru4 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-13-2012, 03:41 PM
  2. Replies: 2
    Last Post: 08-04-2011, 06:42 AM
  3. Update Page Field on selection of another page field in excel pivot table
    By ashwanileon in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-29-2011, 12:33 PM
  4. Checking Web Page(s) within a table.
    By Madlock in forum Excel General
    Replies: 4
    Last Post: 09-19-2010, 06:20 PM
  5. [SOLVED] VBA Code for a pivot table to open database and to reference table current page
    By Pete Straman Straman via OfficeKB.com in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-21-2005, 12:06 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