Working With Comments in VBA

Philip Treacy

August 1, 2019

To start with let's understand that I'm talking about the 'old' style comments like the one on the left.

In Office 365 we now have Threaded Comments which are also being referred to as comments, with the old style comments being referred to as Notes in O365.

But if you are not using O365 then you will still be using the old style comments and still calling them comments. That's not confusing now is it!

Download Example Workbook

Examples of all the code in this post can be downloaded from the sample workbook

Enter your email address below to download the workbook.

By submitting your email address you agree that we can email you our Excel newsletter.

The Comment Object

To work with comments in VBA you'll be mostly using the comment object.

This allows you to do things like delete a comment, change the comment text, or find out things like the comment author or the cell where the comment is.

Adding a Comment

To add a comment you actually use the AddComment method of the Range object

Add a comment

Note: Creating a comment this way results in a comment without the author's name appearing as it would if you inserted the comment manually.

Delete a Comment

Use the Delete method on the comment.

delete a comment

Deleting Specific Author's Comments from Sheet

You can specify the author by passing a string parameter when you call the Sub, rather than hard code the author.

Delete author's comments

Deleting all Comments on a Sheet

You can specify the author by passing a string parameter when you call the Sub, rather than hard code the author.

deleting all comments in sheet

Deleting all Comments in the Workbook

Loop through every comment, on every sheet

deleting all comments in workbook

Find Comments by Author

This will change the color of the cells where a comment exists from the specified author.

find comment by author

Show or Hide Comment Indicator

Comment Indicator Only

comment indicator only

comment indicator only on sheet

Comment and Indicator

comment and indicator

comment and indicator on sheet

No Indicator

no indicator

no indicator on sheet

Change the Background Color of the Comment

Change comment background to green.

changing comment color

green comment color

List All Comments in Workbook

This routine will create a sheet called Comments and then list every comment from every sheet on it.

list all comments in workbook

You can get this code by downloading the example workbook from the top of the post.

5 thoughts on “Working With Comments in VBA”

  1. Hi Phil,

    Probably not many people will care about comments, so I would like to let you know that this is nevertheless a really nice and inspiring post. I like the idea of listing all comments as this opens quite a lot of further possibilities of changing, formatting or deleting specific comments.

    I did not understand the purpose of the Debug.Print section (probably just for counting occurrences). But I thought it would make sense to reduce the possibility that any random colon somewhere in the comment would truncate the listed comment:
    If InStr(Comment_.Text, “:”) = InStr(Comment_.Text, Chr(10)) – 1 Then …

    Thanks!

    Reply

Leave a Comment

Current ye@r *