Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Paste RTF Into A Cell

In VBA I'm trying to paste from a rich text control (RichTx32.ocx) to a
worksheet (Excel 2007) cell but the text always comes out as the unformatted
RTF. How do I paste it so that it appears a properly formatted text?

The code:
Sub RFTTest()
Dim richTextString As String
richTextString = UserForm1.RichTextBox1.TextRTF

Dim myDataObject As New dataObject
Set myDataObject = New dataObject

myDataObject.SetText richTextString ', &HBF01 '(This flag doesn't work
either)
myDataObject.PutInClipboard

Worksheets("Sheet1").Range("D3").Select
Selection.PasteSpecial
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Paste RTF Into A Cell

George,

I don't have that control, but I think you need to copy the rich text to a clipboard object as rich
text, and paste from there. Your richTextString string variable probably dumps out all the
formatting information.

I'm sure that you can google up some examples...

HTH,
Bernie
MS Excel MVP


"George Lee" wrote in message
...
In VBA I'm trying to paste from a rich text control (RichTx32.ocx) to a
worksheet (Excel 2007) cell but the text always comes out as the unformatted
RTF. How do I paste it so that it appears a properly formatted text?

The code:
Sub RFTTest()
Dim richTextString As String
richTextString = UserForm1.RichTextBox1.TextRTF

Dim myDataObject As New dataObject
Set myDataObject = New dataObject

myDataObject.SetText richTextString ', &HBF01 '(This flag doesn't work
either)
myDataObject.PutInClipboard

Worksheets("Sheet1").Range("D3").Select
Selection.PasteSpecial
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Paste RTF Into A Cell

The DataObject only accepts plain text, so that's not going to work (no idea
what you are trying to do with that flag).

It's a long time since I've done anything with the RichTextBox, but from
memory even manually copying the text to the clipboard and then into a cell
doesn't carry formats. However you can copy formats to say Word or even an
RTF, then copy to Excel. You can also write text to file with formats, eg

Dim FF As Integer
Dim rtb As RichTextBox

FF = FreeFile

Set rtb = Me.RichTextBox1
Open "RTBtext.rtf" For Output As #FF
Print #FF, rtb.TextRTF
Close #FF

You could then open the file in Word, copy and paste to Excel.

I know that doesn't help you directly, and pretty sure there's an API
clipboard method, but perhaps some ideas for further search.

Regards,
Peter T



"George Lee" wrote in message
...
In VBA I'm trying to paste from a rich text control (RichTx32.ocx) to a
worksheet (Excel 2007) cell but the text always comes out as the
unformatted
RTF. How do I paste it so that it appears a properly formatted text?

The code:
Sub RFTTest()
Dim richTextString As String
richTextString = UserForm1.RichTextBox1.TextRTF

Dim myDataObject As New dataObject
Set myDataObject = New dataObject

myDataObject.SetText richTextString ', &HBF01 '(This flag doesn't work
either)
myDataObject.PutInClipboard

Worksheets("Sheet1").Range("D3").Select
Selection.PasteSpecial
End Sub



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to cut part of a text from one cell and automatically paste itonto another cell Sonja[_2_] Excel Discussion (Misc queries) 6 August 17th 09 11:35 PM
How can I copy a value from a cell and paste it into another cell while adding it to the previous value in that cell [email protected] Excel Worksheet Functions 2 November 7th 07 09:39 AM
Macro to paste in the active cell the contents of a cell from another file?? LarryB Excel Programming 3 June 12th 06 06:37 PM
Paste Link enters a 0 into the cell where I paste. How do I elemin UNR Excel Discussion (Misc queries) 4 March 28th 05 01:54 AM
Copy and Paste macro needs to paste to a changing cell reference loulou Excel Programming 0 February 24th 05 10:29 AM


All times are GMT +1. The time now is 05:34 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"