|
こんばんは。
例えばこんな感じになるでしょうか。
------ 標準モジュール --------------------------
Sub sample()
Dim txt As New clsMultText
Set txt.CellRange = ActiveCell
txt.Characters(2, 1).Font.ColorIndex = 3
End Sub
----- クラスモジュール clsMultText -------------
Private mCell As Range
Private mLines As Variant
Public Property Set CellRange(ByVal vNewValue As Range)
Set mCell = vNewValue.Cells(1, 1)
mLines = Split(mCell.Value, vbLf)
End Property
Public Property Get Lines(Optional ByVal Line) As Variant
If IsMissing(Line) Then
Lines = mCell.Value
Else
Lines = mLines(Line - 1)
End If
End Property
Public Property Get Characters(Optional Line, Optional Start, Optional Length) As Characters
Dim i As Long, NC As Long
If IsMissing(Line) Then
Set Characters = mCell.Characters
Exit Sub
End If
NC = 0
For i = 1 To Line - 1
NC = NC + Len(mLines(i - 1)) + 1
Next
If IsMissing(Start) Then Start = 1
If IsMissing(Length) Then
Set Characters = mCell.Characters(NC + Start, Len(mLines(i)) - Start + 1)
Else
Set Characters = mCell.Characters(NC + Start, Length)
End If
End Property
|
|