Copy multiline data from html web page and paste into a single cell without losing formatting

deter_dangler

New Member
Joined
May 12, 2013
Messages
4
Hi Everyone,

I have a situation where i have to copy data from web page and paste the data in a single excel cell without losing formatting.

Data on a web page will be like the below:
****************************************
This is in bold
This is in red color and bold!
****************************************I want to paste this data in a excel single cell. Usually when i paste using vba it spreads over different rows..

Any help?
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
It is a very difficult way.
For first drawing near.
1. You create a label shape onto a worksheet and paste a copied from html-page text. It is a full manual step. Indeed, you can create a label shape programmatically, but there is not a way to do such formatting paste.
2. You make a macro using Shape.TextFrame2. Characters properties for setting equal Characters properties of a single cell.

Or another way. To analyze html tags their attributes and css code of a html-page.
Regards
 
Last edited:
Upvote 0
It is a very difficult way.
For first drawing near.
1. You create a label shape onto a worksheet and paste a copied from html-page text. It is a full manual step. Indeed, you can create a label shape programmatically, but there is not a way to do such formatting paste.
2. You make a macro using Shape.TextFrame2. Characters properties for setting equal Characters properties of a single cell.

Or another way. To analyze html tags their attributes and css code of a html-page.
Regards

Hi anvg,

Thank you so much for your reply..

Sorry for the confusion..you can ignore the stars(****). Just to illustrate better, i mentioned in the post.

Can you please elaborate if this is doable? Atleast any clue on where to start from?
 
Upvote 0
As I wrote above it is possible with using an intermediate shape which gets copied web page content.
You can use a macro bellow for copying its font format.
Code:
Public Sub CopyFormat()
    Dim thisShape As Shape, i As Long
    Dim TChar As Characters, RChar As Characters
    Dim TFont As Font, RFont As Font
        
    Set thisShape = ActiveSheet.Shapes(1)
    ActiveCell.Value = thisShape.TextFrame.Characters.Text
    For i = 1 To Len(ActiveCell.Text)
        Set TChar = thisShape.TextFrame.Characters(i, 1)
        Set RChar = ActiveCell.Characters(i, 1)
        If (TChar.Text <> vbLf) And (TChar.Text <> vbCr) And (RChar.Text <> vbLf) And (RChar.Text <> vbCr) Then
            Set TFont = TChar.Font: Set RFont = RChar.Font
            RFont.Name = TFont.Name
            RFont.Color = TFont.Color
            RFont.Size = TFont.Size
            RFont.Bold = TFont.Bold
            RFont.Italic = TFont.Italic
            RFont.Underline = TFont.Underline
            RFont.Subscript = TFont.Subscript
            RFont.Subscript = TFont.Subscript
            DoEvents
         End If
    Next i
End Sub
But this method is very slowly.
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,818
Members
449,049
Latest member
cybersurfer5000

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top