View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
Greg Wilson Greg Wilson is offline
external usenet poster
 
Posts: 747
Default font color of partial cell contents

Thanks Jim for your response. Unfortunately, I need to insert / delete chars
when there are more than 255 chars without loosing existing
character-specific formatting. And I need this to work elegantly. Saving the
individual formats then looping through after each change and reapplying
won't be adequate.

FWIW, I have created my own "edit mode" (subclassing using PeekMessage)
because I can't have the text wrap when it exceeds the visible range. Using
the formula bar or xl's edit mode causes the text to wrap in this situation.
Obviously, when editing (typing in characters, using backspace or the Delete
key etc.) needs to be very fast and smooth. Currently, as soon as I start
editing, character-specific formating is lost. I can reapply after the edit
but that's not what I want.

Greg

"Jim Cone" wrote:

Greg,

You can replace characters using the Mid "Statement".
However, I am guessing that is not exactly what you are looking for...

Sub MoreTextStuff()
Dim strOld As String
strOld = Range("B5").Text
Mid$(strOld, 300, 5) = "stuff"
Range("B5").Value = strOld
End Sub
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



"Greg Wilson"
wrote in message
It isn't the line feed per se but the resetting of the value. It just does
that. That's why Jim set the color after setting the value:

< Range("B5").Value = strName
< Range("B5").Characters(lngCellLength + 1, 255).Font.ColorIndex = 3

Instead of changing the cell's Value property (which will wipe out
character-specific formatting), the Characters method allows you to change a
portion of the text formating while preserving the rest. See also the Insert
and Delete methods. Example:

Range("B5").Characters(12, 4).Font.Color = vbRed
Range("B5").Characters(25, 4).Insert ("Gary") 'Supplants existing characters
Range("B5").Characters(25, 0).Insert ("Gary") 'Inserts without supplanting

However, inserting/deleting will only work up to a max of 255 characters
(inclusive of inserted chars). I hope someone will prove me wrong on this or
suggest a workaround because I have a need for it.

Greg