Format some, not all, text in a comment

J

Jock

Using "Target.Offset(, 1).AddComment", I can add a comment to a cell which
will display values from UserForm 1 TextBox2 and TextBox3.
In between these two values in the comment, I have placed a " v " (to
indicate one party against the other).
I would like to format this "v" to bold and red.
As both TextBox Values are unknown lengths, how can I achieve this?
Many thanks
 
J

Jacob Skaria

Try the below..

Sub Macro1()

Dim objCom As Comment, strText1 As String, strText2 As String

strText1 = "Man"
strText2 = "Animal"

Set objCom = Range("A1").AddComment(strText1 & " v " & strText2)

With objCom.Shape.TextFrame
.Characters(Len(strText1) + 2, 1).Font.ColorIndex = 3
.Characters(Len(strText1) + 2, 1).Font.Bold = True
End With

End Sub
 
J

Jacob Skaria

Another way is to use Instr()

Dim objCom As Comment, strComment As String
strComment = "Man v Animal"
Set objCom = Target.Offset(, 1).AddComment(strComment)
With objCom.Shape.TextFrame
.Characters(InStr(1, objCom.Text, " v ", vbTextCompare),
3).Font.ColorIndex = 3
.Characters(InStr(1, objCom.Text, " v ", vbTextCompare), 3).Font.Bold = True
End With
 

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