Utility – Add Comment
Adds a formatted comment to the specified Excel cell.
If the cell already contains a comment, it will be deleted before adding the new one. The comment is inserted with specified formatting and set to be hidden by default.
VB
Public Sub xlAddComment(Cell As Excel.Range,
Text As String,
Optional Bold As Boolean = False,
Optional Font As String = "Consolas",
Optional Size As Integer = 12)
Try
With Cell
If .Comment IsNot Nothing Then .Comment.Delete()
.AddComment()
.Comment.Visible = False
.Comment.Text(Text)
.Comment.Shape.TextFrame.AutoSize = True
.Comment.Shape.TextFrame.Characters.Font.Bold = Bold
.Comment.Shape.TextFrame.Characters.Font.Size = Size
.Comment.Shape.TextFrame.Characters.Font.Name = Font
End With
Catch ex As Exception
End Try
End Sub