PDA

View Full Version : Rich Text



Adamski
02-26-2009, 05:37 PM
Is it possible to read and write Rich Text to a cell? By setting the cells value property, copy/pasting the cell or any other method. I don't need to use any complicated Rich Text, just the basic bold, italic, underline tags.

e.g.

This is {\i italic and {\b BOLD}} text.

mikerickson
02-26-2009, 06:44 PM
Have you looked at the .Characters propety of a range?
(The two arguments of .Characters property are similar to the last two arguments of the Mid function.)
Record a macro of you setting the middle characters of a cell to red, and that will give you a starting point for those possibilities.

Setting the .Value property of a cell removes all its rich text formatting.

tpoynton
02-26-2009, 06:52 PM
this carbon copies A1 into B1

Sub copycell()
Cells(1, 1).Copy
Cells(1, 2).PasteSpecial xlPasteAll
End Sub

EDIT - perhaps I dont get the question, as I read it totally different than Mikerickson

Adamski
02-27-2009, 03:00 AM
The Rich Text is coming from anoter source external to excel. Specifically, I am reading the text from a DOORS database, but essentially I end up with the text in a string variable.

Now, how do I set the text and formatting of a cell with the string?
I can parse the string myself and read the tags, setting each characters formatting as necessary, but I thaught there would be a easier, automatic way. It is slow to parse each string and format the characters. Using the clipboard seemed like a plan and then PasteSpecial but I can't get it working. Ideally I want to read a cell back as Rich Text too so I can write a string to the database, but that is not as important.

The text may need to be surrounded by the \rtf1 tag I guess, but that is not problem:

{\rtf1 This is {\i italic and {\b BOLD}} text.}