Partilhar via


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 application-level projects for Excel 2013 and Excel 2010. For more information, see Features Available by Office Application and Project Type.

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

  • 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 Sub ShowOrHideComments(ByVal show As Boolean)
        Dim i As Integer 
        For i = 1 To Me.Comments.Count
            Me.Comments(i).Visible = show
        Next 
    End Sub
    
    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 add-in

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

    Private Sub ShowOrHideComments(ByVal show As Boolean)
        Dim worksheet As Excel.Worksheet = CType(Application.ActiveSheet, Excel.Worksheet)
        Dim i As Integer 
        For i = 1 To worksheet.Comments.Count
            worksheet.Comments(i).Visible = show
        Next 
    End Sub
    
    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;
        }
    }
    

See Also

Tasks

How to: Programmatically Add and Delete Worksheet Comments

Concepts

Working with Worksheets

Host Items and Host Controls Overview