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.
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
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.
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.
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 the Workbook
Loop through every comment, on every sheet
Find Comments by Author
This will change the color of the cells where a comment exists from the specified author.
Show or Hide Comment Indicator
Comment Indicator Only
Comment and Indicator
No Indicator
Change the Background Color of the Comment
Change comment background to green.
List All Comments in Workbook
This routine will create a sheet called Comments and then list every comment from every sheet on it.
You can get this code by downloading the example workbook from the top of the post.
J. Woolley
You might be interested in my macros to format, resize, and reposition unthreaded cell Comments (now called Notes). See my web site at https://sites.google.com/view/MyExcelToolbox/
Achieving a satisfactory resize method was particularly difficult.
Philip Treacy
Thanks
uttam kumar sarker
Awesome post!!!
Very informative, all the tips you discussed in post are valuable.
Matthias
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!
Philip Treacy
Thanks Matthias.
The Debug.Print statement is only there for me for testing, I forgot to comment it out.
Phil