Show HTML code as "HTML preview" within an excel cells

Anonymous
2014-10-13T12:38:10+00:00

Hello,

I have a row with cells containing text strings with HTML code inside. I would like to see just HTML preview (no code) within cells. I would like to still have HTML code inside the cell, but it apears as text without <> etc...

Is that possible?

I tried

Sub Sample2()

    Dim Ie As Object

    Set Ie = CreateObject("InternetExplorer.Application")

    With Ie

        .Visible = False

        .Navigate "about:blank"

        .document.body.InnerHTML = Sheets("Sheet1").Range("A1").Value

        .document.body.createtextrange.execCommand "Copy"

        ActiveSheet.Paste Destination:=Sheets("Sheet1").Range("A1")

        .Quit

    End With

End Sub

I get stuck with this line .document.body.createtextrange.execCommand "Copy"

could someone help me?

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes

12 answers

Sort by: Most helpful
  1. Anonymous
    2014-10-15T15:22:44+00:00

    it is ok, i am glad that you answered :) i am newbie with vba

    may i ask you how to change this line

    Dim objData As DataObject ' Set a reference to MS Forms 2.0 ?

    thank you so much guys

    0 comments No comments
  2. Andreas Killer 144K Reputation points Volunteer Moderator
    2014-10-15T16:28:25+00:00

    may i ask you how to change this line

    Dim objData As DataObject ' Set a reference to MS Forms 2.0 ?

    You can't, you must set the reference.

    BTW, this reference is set automatically when you add an ActiveX control anywhere in your file. Means you can add a commandbitton to your file and remove it to set the reference.

    Or set the reference manually in the VBA editor under Tools\References or execute the sub below.

    Andreas.

    Sub SetRef()

      On Error Resume Next

      'Microsoft Forms 2.0 Object Library

      Application.VBE.ActiveVBProject.References.AddFromGuid _

        "{0D452EE1-E08F-101A-852E-02608C4D0BB4}", 2, 0

    End Sub

    1 person found this answer helpful.
    0 comments No comments