Excel, Comment

accessman2

Registered User.
Local time
Today, 05:23
Joined
Sep 15, 2005
Messages
335
Hi,
suppose the cmt is string variable


cmt = "Invoice 1:" & Chr(10)
cmt = cmt & "Num: 1" & Chr(10)
cmt = cmt & "Company: Microsoft"
cmt = cmt & Chr(10)
cmt = cmt & "Invoice 2:" & Chr(10)
cmt = cmt & "Num: 2" & Chr(10)
cmt = cmt & "Company: IBM"

.Worksheets(1).Cells(1, 5).AddComment cmt
.Worksheets(1).Cells(1, 5).Comment.Shape.TextFrame.Characters.Font.Bold = False

I used the above code to do the comment, but I want to set "Invoice 1" and "Invoice 2" to be Bold = True only.

How can I change?

Does anybody know that? Thanks.
 
Hi, accessman2,

please have a look at this code:

Code:
Const cstrINV1 As String = "Invoice 1:"
Const cstrINV2 As String = "Invoice 2:"
Dim cmt As String
Dim intStart1  As Integer
Dim intStart2 As Integer
Dim intCounter As Integer

cmt = cstrINV1 & Chr(10)
cmt = cmt & "Num: 1" & Chr(10)
cmt = cmt & "Company: Microsoft"
cmt = cmt & Chr(10)
cmt = cmt & cstrINV2 & Chr(10)
cmt = cmt & "Num: 2" & Chr(10)
cmt = cmt & "Company: IBM"

intStart1 = InStr(1, cmt, cstrINV1)
intStart2 = InStr(1, cmt, cstrINV2)

Worksheets(1).Cells(1, 5).AddComment cmt
With Worksheets(1).Cells(1, 5).Comment.Shape.TextFrame
    .Characters(Start:=intStart1, Length:=Len(cstrINV1)).Font.Bold = True
    .Characters(Start:=intStart2, Length:=Len(cstrINV2)).Font.Bold = True
    .AutoSize = True
End With
If this would take more variables to find maybe use an array for the terms and the starting point within the comment and loop through the array...

Ciao,
Holger
 

Users who are viewing this thread

Back
Top Bottom