html tags with a cell

D

dan

I thought I could use html tags within a cell to bold
cetain words etc. such as My name is <B>Dan<b> and I
want to be bold but it does not work.
 
G

Guest

I never did post a question with this statement - is
there a way to format a part of a cell?
 
J

jaf

Characters Property Example

This example formats the third character in cell A1 on Sheet1 as bold.

With Worksheets("Sheet1").Range("A1")
.Value = "abcdefg"
.Characters(3, 1).Font.Bold = True
End With
 
G

Guest

You, the man!

Can I apply a format to any string or just to the
contents of a range???

Thanks
 
C

Colo

Hello dan,

Here is a test code what I wrote(for fun!). :D
Try input text in a cell with <b> </b> Tags.



Code:
--------------------

Option Explicit

'Written by Colo 18 Dec 2003

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
BoldWithTag Target
End Sub

Private Sub BoldWithTag(ByVal Target As Range)
Dim c As Range
Dim blnFlag As Boolean
Dim i As Long, st As Long, ed As Long
Dim Start() As Long, Length() As Long
If Target.Rows.Count = Rows.Count Then Exit Sub
If Target.Columns.Count = Columns.Count Then Exit Sub
For Each c In Target
With c
Do
st = InStr(1, .Value, "<b>", 1)
If st = 0 Then Exit Do
ed = InStr(st, .Value, "</b>", 1)
If ed = 0 Then Exit Do
blnFlag = True
.Value = Left(.Value, st - 1) & _
Mid(.Value, st + 3, ed - st - 3) & _
Right(.Value, Len(.Value) - ed - 3)
i = i + 1
ReDim Preserve Start(1 To i): ReDim Preserve Length(1 To i)
Start(i) = st: Length(i) = ed - st - 3
Loop
If blnFlag Then
For i = LBound(Start) To UBound(Start)
c.Characters(Start(i), Length(i)).Font.Bold = True
Next
End If
st = 0: ed = 0: i = 0: Erase Start: Erase Length: blnFlag = False
End With
Next
End Sub

--------------------
 
T

Tom Ogilvy

Any object which has the characters property and supports Rich Text
Formatting. For example, the text of cell comments, text in the textbox
from the drawing toolbar.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top