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>
Bookmarks