Html Tags for Specific Words in a Cell

J

Jaycee Sagaral

Hi Everyone,

I have problem putting up html tags to every specific word in a cell.
Let's say this praise.

JUAN: Honey, bakit MALI ang pinaglalagyan mong DALIRI ng
WEDDING RING natin?
MRS: Siyempre para TERNO! Mali din naman ang NAPANGASAWA ko eh![/
QUOTE]

The above is a conversation and I'd like to put "<b>" and "</b>" at
the beginning and end to make the talking character's name in bold
format when i uploaded it in the internet.

I target this result:

<b>JUAN</b>: Honey, bakit MALI ang pinaglalagyan mong DALIRI ng
WEDDING RING natin?
<b>MRS</b>: Siyempre para TERNO! Mali din naman ang NAPANGASAWA ko eh!

What I am thinking is replace first the : by the tag "</b>" (using
usual excel feature) then add "<b>" at the beginning of a word that
contains "</b>"

Thats the problem. How can I replace every word in a cell that
contains the "</b>". Or if there is a better idea, it will be much
appreciated.

Hope someone can help me with this. Thank you.
 
R

Ron Rosenfeld

Hi Everyone,

I have problem putting up html tags to every specific word in a cell.
Let's say this praise.

JUAN: Honey, bakit MALI ang pinaglalagyan mong DALIRI ng
WEDDING RING natin?
MRS: Siyempre para TERNO! Mali din naman ang NAPANGASAWA ko eh![/
QUOTE]

The above is a conversation and I'd like to put "<b>" and "</b>" at
the beginning and end to make the talking character's name in bold
format when i uploaded it in the internet.

I target this result:

<b>JUAN</b>: Honey, bakit MALI ang pinaglalagyan mong DALIRI ng
WEDDING RING natin?
<b>MRS</b>: Siyempre para TERNO! Mali din naman ang NAPANGASAWA ko eh!

What I am thinking is replace first the : by the tag "</b>" (using
usual excel feature) then add "<b>" at the beginning of a word that
contains "</b>"

Thats the problem. How can I replace every word in a cell that
contains the "</b>". Or if there is a better idea, it will be much
appreciated.

Hope someone can help me with this. Thank you.

The devil is in the minute details. If the speaking character is always a single word (no spaces or punctuation), and followed by a colon; and if there are no other colons in the text other than those preceded by what you want to bold, a VBA solution is fairly straightforward.

But if either of those details is not always going to be the case, you need to present information about the variability in the presentation so as to take those variations into account.

A sample VBA macro, that assumes the source data is in column A, and puts the "bolded" version in column B:

To enter this Macro (Sub), <alt-F11> opens the Visual Basic Editor.
Ensure your project is highlighted in the Project Explorer window.
Then, from the top menu, select Insert/Module and
paste the code below into the window that opens.

To use this Macro (Sub), <alt-F8> opens the macro dialog box. Select the macro by name, and <RUN>.

======================================
Option Explicit
Sub BoldSpeaker()
Dim rg As Range, c As Range
Dim re As Object
Const sPat As String = "(\b\w+)(?=:)"
Const sRepl As String = "<b>$1<b>"
Set rg = Range("A1", Cells(Cells.Rows.Count, "A").End(xlUp))
Set re = CreateObject("vbscript.regexp")
re.Global = True
re.Pattern = sPat
For Each c In rg
c.Offset(0, 1).Value = re.Replace(c.Text, sRepl)
Next c
End Sub
====================================

This routine makes use of regular expressions, which are quite useful for complicated text manipulations.
 
G

GS

It happens that Jaycee Sagaral formulated :
Hi Everyone,

I have problem putting up html tags to every specific word in a cell.
Let's say this praise.

JUAN: Honey, bakit MALI ang pinaglalagyan mong DALIRI ng
WEDDING RING natin?
MRS: Siyempre para TERNO! Mali din naman ang NAPANGASAWA ko eh![/
QUOTE]

The above is a conversation and I'd like to put "<b>" and "</b>" at
the beginning and end to make the talking character's name in bold
format when i uploaded it in the internet.

I target this result:

<b>JUAN</b>: Honey, bakit MALI ang pinaglalagyan mong DALIRI ng
WEDDING RING natin?
<b>MRS</b>: Siyempre para TERNO! Mali din naman ang NAPANGASAWA ko eh!

What I am thinking is replace first the : by the tag "</b>" (using
usual excel feature) then add "<b>" at the beginning of a word that
contains "</b>"

Thats the problem. How can I replace every word in a cell that
contains the "</b>". Or if there is a better idea, it will be much
appreciated.

Hope someone can help me with this. Thank you.

I suspect that, as with Word, if you bold the individual text within a
cell that you want bold then it will get the correct tags when you
export as HTML. IOW, the formatting gets tagged during the HTML
conversion process.
 
Top