Share via


NamedRange.AddComment(Object) Method

Definition

Adds a comment to the NamedRange control.

public Microsoft.Office.Interop.Excel.Comment AddComment (object Text);
abstract member AddComment : obj -> Microsoft.Office.Interop.Excel.Comment
Public Function AddComment (Optional Text As Object) As Comment

Parameters

Text
Object

The comment text.

Returns

Examples

The following code example uses the AddComment method to add the comment "This is Martha's range." to a NamedRange control that includes cell A1.

This example is for a document-level customization.

private void FindMarthaInTheRange()
{
    this.Range["A1"].Value2 = "Martha lives on a vineyard";

    Microsoft.Office.Tools.Excel.NamedRange namedRange1 =
        this.Controls.AddNamedRange(this.Range["A2"],
        "namedRange1");

    namedRange1.AddComment("This is Martha's range.");
    namedRange1.Value2 = namedRange1.AutoComplete("Ma");

    if (MessageBox.Show("Clear the range?", "Test",
        MessageBoxButtons.YesNo) == DialogResult.Yes)
    {
        namedRange1.Clear();
    }
}
Private Sub FindMarthaInTheRange()
    Me.Range("A1").Value2 = "Martha lives on a vineyard"

    Dim namedRange1 As Microsoft.Office.Tools.Excel.NamedRange _
        = Me.Controls.AddNamedRange(Me.Range("A2"), _
        "namedRange1")

    namedRange1.AddComment("This is Martha's range.")
    namedRange1.Value2 = namedRange1.AutoComplete("Ma")

    If MessageBox.Show("Clear the range?", "Test", _
        MessageBoxButtons.YesNo) = DialogResult.Yes Then
        namedRange1.Clear()
    End If
End Sub

Remarks

Comments can only be added to NamedRange controls that consist of a single cell. You cannot add a comment if the NamedRange control has more than one cell.

Optional Parameters

For information on optional parameters, see Optional Parameters in Office Solutions.

Applies to