Search notes:

Excel VBA: Worksheet.PasteSpecial

Rendering HTML text in a cell

We need to add a reference to MS Forms which can be created by executing the following line in the immediate window.
application.vbe.activeVBProject.references.addFromGuid "{0D452EE1-E08F-101A-852E-02608C4D0BB4}", 2, 0
The following function (sub) can then be used to render a given HTML in the specified cell:
option explicit

public sub htmlToCell(html as string, cel as range)

   application.enableEvents = false

   dim objData as new msForms.dataObject
   objData.setText html
   objData.putInClipboard
   cel.select
   cel.parent.pasteSpecial format := "unicode text"

   application.enableEvents = true

end sub
Ideas to test the function:
htmlToCell "<html><table><tr><td>x</td><td>xxxxxx</td></tr><tr><td>yyyyyy</td><td>yy</td></tr></html>", cells(5,3)
htmlToCell "<html><i>Italic</i>, <b>bold</b> and <font color=red>red</font></html>", cells(10, 10)

See also

The worksheet object.

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/Microsof...', 1747748137, '18.217.121.234', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/Microsoft/Office/Excel/Object-Model/Worksheet/PasteSpecial(63): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78