Microsoft Office Tutorials and References
In Depth Information
The Comment Object: A Case Study
Methods of a Comment object
Table 7-2 shows the methods that you can use with a Comment object. Again, these methods
perform common operations that you may have performed manually with a comment at some
point . . . but you probably never thought of these operations as methods.
Table 7-2: Methods of a Comment Object
Deletes a comment.
Returns a Comment object that represents the next comment in the worksheet.
Returns a Comment object that represents the previous comment in the worksheet.
Returns or sets the text in a comment (takes three arguments).
You may be surprised to see that Text is a method rather than a property, which leads
to an important point: The distinction between properties and methods isn’t always
clear-cut, and the object model isn’t perfectly consistent. In fact, it’s not really
important that you distinguish between properties and methods. As long as you get the
syntax correct, it doesn’t matter whether a word in your code is a property or a method.
The Comments collection
Recall that a collection is a group of like objects. Every worksheet has a Comments collection,
which consists of all Comment objects on the worksheet. If the worksheet has no comments, this
collection is empty. Comments appear in the collection based on their position in the worksheet:
left-to-right and then top-to-bottom.
For example, the following code refers to the first comment on Sheet1 of the active workbook:
The following statement displays the text contained in the first comment on Sheet1 :
Unlike most objects, a Comment object doesn’t have a Name property. Therefore, to refer to a
specific comment, you must either use an index number or (more frequently) use the Comment
property of a Range object to return a specific comment.