Class Comment (Excel VBA)

The class Comment represents a cell comment.

Item

To use a Comment class variable it first needs to be instantiated, for example

Dim cmm as Comment
Set cmm = ActiveCell.Comment

The following procedures can be used to set variables of type Comment: Next, Previous, Comments.Item, Range.AddComment and Range.Comment.

For Each

Here is an example of processing the Comment items in a collection.

Dim cmm As Comment
For Each cmm In Application.Comments
	
Next cmm

Author

Returns the author of the comment.

Dim strAuthor As String
strAuthor = ActiveCell.Comment.Author

Delete

Deletes the object.

ActiveCell.Comment.Delete

Next

Returns a Comment object that represents the next comment.

This method works only on one sheet. Using this method on the last comment on a sheet returns Null (not the next comment on the next sheet).

Dim cmmNext As Comment
Set cmmNext = ActiveCell.Comment.Next()

Previous

Returns a Comment object that represents the previous comment.

This method works only on one sheet. Using this method on the first comment on a sheet returns Null (not the last comment on the previous sheet).

Dim cmmPrevious As Comment
Set cmmPrevious = ActiveCell.Comment.Previous()

Shape

Returns a Shape object that represents the shape attached to the specified comment.

Dim shpShape As Shape
Set shpShape = ActiveCell.Comment.Shape

Text

Sets comment text.

Text (Text, Start, Overwrite)

Dim strText As String
strText = ActiveCell.Comment.Text()

Arguments

Optional arguments

The following arguments are optional

Text - The text to be added

Start - The character number where the added text will be placed. If this argument is omitted, any existing text in the comment is deleted

Overwrite - False to insert the text. The default value is True (text is overwritten)

Visible

Returns or sets a Boolean value that determines whether the object is visible.

ActiveCell.Comment.Visible = True

Comments.Count

Returns a Long value that represents the number of objects in the collection.

Dim lngCount As Long
lngCount = ActiveSheet.Comments.Count

Comments.Item

Returns a single object from a collection.

Item (Index)

Index: The index number for the object.

Dim cmm As Comment
Set cmm = ActiveSheet.Comments(Index:=1)