Results 1 to 2 of 2

How do I insert an HTML table into a worksheet

Threaded View

  1. #1
    Registered User
    Join Date
    12-02-2010
    Location
    Huntington, New York, USA
    MS-Off Ver
    Excel 2007
    Posts
    20

    How do I insert an HTML table into a worksheet

    Hi All:

    Using VBA in Excel I am trying to insert a table coded in HTML (see below) into a worksheet. If I manually copy the code text to the clipboard and paste it into a cell, the table is displayed with the rows and columns as defined by the HTML tags ... so I thought to do this easily beginning with a string variable, TableVariable, containing the code as follows:
     'copy the code in TableVariable to the clipboard   
        Dim DataObj As New MSForms.DataObject
        Dim S As String
        S = Tablevariable
        DataObj.SetText S
        DataObj.PutInClipboard
    'Retrieve the code and paste it into a worksheet
         ActiveSheet.Paste Destination:=Worksheets("Sheet1").Range("A1:C3")


    Doesn't Work for two reasons ...

    1. I am using 64 bit Windows 7 Pro and the MSForms2_0.dll file is missing ... so I can't reference the DataObject Class. Certainly the class is defined in some type library, somewhere, but I haven't found it (except in .NET) and can find nothing about it in VBA on the web.
    2. The paste method stuffs all the code into cell A1 and ignores the HTML tags. When I copy and paste the code manually the table is perfect.

    If there's a different approach, I am not committed to the clipboard, but can't think of another algorithm. Please help get me on the right track!

    Thanks,

    Stosh

    Here's the HTML code for a 3 X 3 table ...
    <table class=MsoTableGrid border=1 cellspacing=0 cellpadding=0
     style='border-collapse:collapse;border:none'>
     <tr>
      <td width=213 valign=top style='width:159.6pt;border:solid windowtext 1.0pt;
      padding:0in 5.4pt 0in 5.4pt'>
      <p class=MsoNormal>one<o:p></o:p></p>
      </td>
      <td width=213 valign=top style='width:159.6pt;border:solid windowtext 1.0pt;
      border-left:none;padding:0in 5.4pt 0in 5.4pt'>
      <p class=MsoNormal>two<o:p></o:p></p>
      </td>
      <td width=213 valign=top style='width:159.6pt;border:solid windowtext 1.0pt;
      border-left:none;padding:0in 5.4pt 0in 5.4pt'>
      <p class=MsoNormal>three<o:p></o:p></p>
      </td>
     </tr>
     <tr>
      <td width=213 valign=top style='width:159.6pt;border:solid windowtext 1.0pt;
      border-top:none;padding:0in 5.4pt 0in 5.4pt'>
      <p class=MsoNormal>four<o:p></o:p></p>
      </td>
      <td width=213 valign=top style='width:159.6pt;border-top:none;border-left:
      none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
      padding:0in 5.4pt 0in 5.4pt'>
      <p class=MsoNormal>five<o:p></o:p></p>
      </td>
      <td width=213 valign=top style='width:159.6pt;border-top:none;border-left:
      none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
      padding:0in 5.4pt 0in 5.4pt'>
      <p class=MsoNormal>six<o:p></o:p></p>
      </td>
     </tr>
     <tr>
      <td width=213 valign=top style='width:159.6pt;border:solid windowtext 1.0pt;
      border-top:none;padding:0in 5.4pt 0in 5.4pt'>
      <p class=MsoNormal>seven<o:p></o:p></p>
      </td>
      <td width=213 valign=top style='width:159.6pt;border-top:none;border-left:
      none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
      padding:0in 5.4pt 0in 5.4pt'>
      <p class=MsoNormal>eight<o:p></o:p></p>
      </td>
      <td width=213 valign=top style='width:159.6pt;border-top:none;border-left:
      none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
      padding:0in 5.4pt 0in 5.4pt'>
      <p class=MsoNormal>nine<o:p></o:p></p>
      </td>
     </tr>
    </table>
    Last edited by srschiller; 12-08-2010 at 10:14 AM. Reason: Clarified title

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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