Quantcast
Channel: Microsoft Community - Super Fresh
Viewing all articles
Browse latest Browse all 1237235

Paste multi-line value in one cell.

$
0
0

Hi All,

I have this use case where I need to first copy the html data from excel and convert it to normal text with proper formatting as defined by html tags and then paste that text in the same cell without html tags.

Right now I am using the below code:

Sub Darveena123()

    Dim cnt As Integer
    Dim x As Integer
   Dim a As String
   Dim b As String

   a = "<html>"
   b = "</html>"
    cnt = Worksheets("Sheet1").Cells.SpecialCells(xlCellTypeLastCell).Row
    For x = 2 To cnt

    Dim Target As Range
    Set Target = ActiveSheet.Cells(x, 1)
    Dim objData As DataObject
    Dim sHTML As String
    Dim sSelAdd As String

    Application.EnableEvents = False

            Set objData = New DataObject
            sHTML = Target.Text
            sHTML = a & sHTML & b
            sHTML = Replace(sHTML, "<html>", "<html><style>br{mso-data-placement:same-cell;}</style>")

            objData.SetText sHTML
            objData.PutInClipboard
            Target.Select
            Application.SendKeys ("{F2}")
            ActiveSheet.PasteSpecial Format:="Unicode Text"

    Application.EnableEvents = True

    Next x


End Sub

With the help of above code I am able to copy and convert the below sample cell value as normal text:

<P>“<EM>The strength of a team is each individual member...the strength of each member is the team</EM>” -&nbsp;Coach Phil Jackson of Chicago Bulls</P>
<P>Air Canada CoE organized a fun-filled team building exercise recently for&nbsp;their Operations and Support Functions. Around 32 employees divided into 8 teams, criss-crossed the city in a game of Treasure Hunt, racking their brains and looking for those elusive clues. They named this exercise ‘Let’s Talk,’ signifying better communication between peers. </P>
<P>The teams were given the first clue for the day in the office, which was hidden in a word scramble. Once the teams solved this, they discovered their next destination – the coffee shop ‘Mocha,’ where they reached just on time for lunch. The teams were specifically asked to come ‘on time’ and not before or after the scheduled time. ‘Plan well and execute rather than jumping in without a plan’ was the first learning for the team members!</P><IMG src=""http://web01.intranet.genpact.com/comm/images/Air-Canada-2.jpg"" align=right></STRONG> 

But I am still not able to paste it in the same cell. Everything just gets scattered in several cells.

Please suggest. Any help will be highly appreciated.

Thank you.

Regards,

Darveena


Viewing all articles
Browse latest Browse all 1237235

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>