Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Find formatting in text in cell, insert tags around formatting.

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Find formatting in text in cell, insert tags around formatting.

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
...
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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Find formatting in text in cell, insert tags around formatting

Thanks!! Works like a charm.

-Carl


"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
...
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



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
Find Replace loses text properties/formatting no1jimmyman Excel Worksheet Functions 1 February 3rd 11 09:56 PM
How to Find Incompatible Cell Formatting XL 2003 / 2007 ?? monir Excel Discussion (Misc queries) 3 July 9th 08 07:17 PM
Find and Replace formatting formats the ENTIRE cell Duy Nguyen Excel Discussion (Misc queries) 2 April 16th 07 02:28 PM
expanding custom formatting without removing existing cell formatting? Keith Excel Worksheet Functions 3 December 27th 06 01:54 PM
Conditional Formatting based on text within a cell w/ text AND num Shirley Excel Worksheet Functions 2 December 22nd 06 01:40 AM


All times are GMT +1. The time now is 09:25 AM.

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

About Us

"It's about Microsoft Excel"