Dela via


How to: Display Worksheet Comments

Applies to

The information in this topic applies only to the specified Visual Studio Tools for Office projects and versions of Microsoft Office.

Project type

  • Document-level projects

  • Application-level projects

Microsoft Office version

  • Excel 2003

  • Excel 2007

For more information, see Features Available by Application and Project Type.

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

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: Add and Delete Worksheet Comments

Concepts

Working with Worksheets

Host Items and Host Controls Overview

Change History

Date

History

Reason

July 2008

Added a code example that can be used in an application-level add-in.

Customer feedback.