View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Colo[_38_] Colo[_38_] is offline
external usenet poster
 
Posts: 1
Default html tags with a cell

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

--------------------



---
Message posted from http://www.ExcelForum.com/