Programmatically add and delete worksheet comments
You can programmatically add and delete comments in Microsoft Office Excel worksheets. Comments can be added only to single cells, not to multi-cell ranges.
Applies to: The information in this topic applies to document-level projects and VSTO Add-in projects for Excel. For more information, see Features available by Office application and project type.
Add and delete a comment in a document-level project
The following examples assume that there is a single-cell NamedRange control named dateComment
on a worksheet named Sheet1
.
To add a new comment to a named range
Call the AddComment method of the NamedRange control and supply the comment text. This code must be placed in the
Sheet1
class.
To delete a comment from a named range
Verify that a comment exists on the range and delete it. This code must be placed in the
Sheet1
class.
Add and delete a comment in a VSTO Add-in project
The following examples assume that there is a single-cell Range named dateComment
on the active worksheet.
To add a new comment to an Excel range
Call the AddComment method of the Range and supply the comment text.
To delete a comment from an Excel range
Verify that a comment exists on the range and delete it.
Related content
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for