ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Find formatting in text in cell, insert tags aroundformatting (https://www.excelbanter.com/excel-programming/421963-find-formatting-text-cell-insert-tags-aroundformatting.html)

Kris Gevers

Find formatting in text in cell, insert tags aroundformatting
 
Hi, I just read this interesting topic, as we are looking for this for months... So, I tried to do this but don't know where to start? Is this info regarding a macro? Where do I need to add this formula?

grtz

K.

EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com

Rick Rothstein

Find formatting in text in cell, insert tags around formatting
 
What "interesting topic"? Your message is the only one in this thread. Why
don't you tell us what you are trying to do (in some detail please) and
let's see if someone here can give you code to do it.

--
Rick (MVP - Excel)


"Kris Gevers" wrote in message ...
Hi, I just read this interesting topic, as we are looking for this for
months... So, I tried to do this but don't know where to start? Is this
info regarding a macro? Where do I need to add this formula?

grtz

K.

EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com



Sergey R

Find formatting in text in cell, insert tags around formatting
 
This is very nice macro, but not a solution for serious documents (about 120000 cells). Is it possible to do this using MSExcel directly without Vba?

On Wednesday, February 27, 2008 1:58 PM Carl wrote:


Hi,

I have cells containing bold or italic words within the text. I would like
to be able to search for the various formatting within the cells, insert tags
around the formatted words, and then remove the formatting.

The tags look like: <emph render="name of formatting"formatted words</emph

Example:
Suppose the words "quick brown" were in bold, the text should look like:
"The <emph render="bold"quick brown</emph fox jumps over..."

Is there an easy way to search for formatting within a cell and identify the
formatted words so that the tags can be inserted?

Thank
-Carl



On Wednesday, February 27, 2008 3:50 PM Rick Rothstein \(MVP - VB\) wrote:


Give the subroutine after my signature a try. To use it, simply call it
while passing in the cell reference of the text you want to parse; something
like this...

ParseTxt ActiveSheet.Range("A1")

Note that this code will handle one font style embedded within another; so,
you can have a word that is both bold and italic; or your can have a bold
word embedded within a longer, italicized piece of text (or vice versa).

Rick

Sub ParseTxt(Cel As Range)
Dim X As Long
Dim Txt As String
Dim BoldOn As Boolean
Dim ItalicsOn As Boolean
If Cel.Count < 1 Then Exit Sub
For X = 1 To Len(Cel.Value)
If Cel.Characters(X, 1).Font.Italic And Not ItalicsOn Then
ItalicsOn = True
Txt = Txt & "<emph render=""italic"""
End If
If Cel.Characters(X, 1).Font.Bold And Not BoldOn Then
BoldOn = True
Txt = Txt & "<emph render=""bold"""
End If
Txt = Txt & Mid$(Cel.Value, X, 1)
If Not Cel.Characters(X, 1).Font.Bold And BoldOn Then
BoldOn = False
Txt = Left(Txt, Len(Txt) - 1) & "</emph" & Right(Txt, 1)
End If
If Not Cel.Characters(X, 1).Font.Italic And ItalicsOn Then
ItalicsOn = False
Txt = Left(Txt, Len(Txt) - 1) & "</emph" & Right(Txt, 1)
End If
Next
If BoldOn Then
Txt = Txt & "</emph"
End If
If ItalicsOn Then
Txt = Txt & "</emph"
End If
Cel.Font.Italic = False
Cel.Font.Bold = False
Cel.Value = Txt
End Sub



"CarlC" wrote in message
...



On Wednesday, February 27, 2008 4:26 PM Carl wrote:


Thanks!! Works like a charm.

-Carl


"Rick Rothstein (MVP - VB)" wrote:



On Monday, January 05, 2009 7:33 AM Kris Gevers wrote:


Hi, I just read this interesting topic, as we are looking for this for months... So, I tried to do this but don't know where to start? Is this info regarding a macro? Where do I need to add this formula?



grtz



K.



Submitted via EggHeadCafe
ASP.NET Base64 Image Encoding via the Data: protocol
http://www.eggheadcafe.com/tutorials...-protocol.aspx



All times are GMT +1. The time now is 02:10 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com