How to: Programmatically Display Worksheet Comments

 

You can programmatically show and hide comments in Microsoft Office Excel worksheets.

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.

To display all comments on a worksheet in a document-level customization

  1. Set the Visible property to true if you want to show comments; otherwise false. This code must be placed in a sheet class, not in the ThisWorkbook class.

            private void ShowOrHideComments(bool show)
            {
                for (int i = 1; i <= this.Comments.Count; i++)
                {
                    this.Comments[i].Visible = show;
                }
            }
    

To display all comments on a worksheet in an application-level VSTO Add-in

  1. Set the Visible property to true if you want to show comments; otherwise false.

            private void ShowOrHideComments(bool show)
            {
                Excel.Worksheet worksheet = (Excel.Worksheet)Application.ActiveSheet;
                for (int i = 1; i <= worksheet.Comments.Count; i++)
                {
                    worksheet.Comments[i].Visible = show;
                }
            }
    

Working with Worksheets
How to: Programmatically Add and Delete Worksheet Comments
Host Items and Host Controls Overview

Show: