Adding a new Comment object

You might have noticed that the list of methods for the Comment object doesn't include a method to add a new comment. This is because the AddComment method belongs to the Range object. The following statement adds a comment (an empty comment) to cell A1 on the active worksheet:


If you consult the Help system, you'll discover that the AddComment method takes an argument that represents the text for the comment. Therefore, you can add a comment and then add text to the comment with a single statement, like this:

Range("A1").AddComment "Formula developed by JW."

The AddComment method generates an error if the cell already contains a comment.

If you'd like to see these Comment object properties and methods in action, check out the example workbook on the companion CD-ROM. This workbook contains several examples that manipulate Comment objects with VBA code. You probably won't understand all the code, but you will get a feel for how you can use VBA to manipulate an object.

Was this article helpful?

0 0

Post a comment