Share via


NamedRange.NoteText(Object, Object, Object) Method

Definition

Gets or sets the cell note associated with the cell in the upper-left corner of the NamedRange control.

public string NoteText (object Text, object Start, object Length);
abstract member NoteText : obj * obj * obj -> string
Public Function NoteText (Optional Text As Object, Optional Start As Object, Optional Length As Object) As String

Parameters

Text
Object

The text to add to the note (up to 255 characters). The text is inserted starting at position Start, replacing Length characters of the existing note. If this argument is omitted, this method returns the current text of the note starting at position Start, for Length characters.

Start
Object

The starting position for the text that is set or returned. If this argument is omitted, this method starts at the first character. To append text to the note, specify a number larger than the number of characters in the existing note.

Length
Object

The number of characters to be set or returned. If this argument is omitted, Microsoft Office Excel sets or returns characters from the starting position to the end of the note (up to 255 characters). If there are more than 255 characters from Start to the end of the note, this method returns only 255 characters.

Returns

Examples

The following code example demonstrates how to set a variety of formatting and display characteristics of a NamedRange control named NamedRange1. In particular, this example uses the NoteText method to add a note to NamedRange1 with the text This is a Formatting test.

This example is for a document-level customization.

private void SetRangeFormats()
{
    Microsoft.Office.Tools.Excel.NamedRange namedRange1 =
        this.Controls.AddNamedRange(this.Range["A1", "A5"],
        "namedRange1");

    namedRange1.NoteText("This is a Formatting test");
    namedRange1.Value2 = "Martha";
    namedRange1.Font.Name = "Verdana";
    namedRange1.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;
    namedRange1.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
    namedRange1.BorderAround(missing, Excel.XlBorderWeight.xlThick, 
        Excel.XlColorIndex.xlColorIndexAutomatic);
    namedRange1.AutoFormat(Excel.XlRangeAutoFormat.xlRangeAutoFormat3DEffects1,
        true, false, true, false, true, true);

    if (MessageBox.Show("Clear the formatting and notes?", "Test",
        MessageBoxButtons.YesNo) == DialogResult.Yes)
    {
        namedRange1.ClearFormats();
        namedRange1.ClearNotes();
    }
}
Private Sub SetRangeFormats()
    Dim namedRange1 As Microsoft.Office.Tools.Excel.NamedRange _
        = Me.Controls.AddNamedRange(Me.Range("A1", "A5"), _
        "namedRange1")

    namedRange1.NoteText("This is a Formatting test", , )
    namedRange1.Value2 = "Martha"
    namedRange1.Font.Name = "Verdana"
    namedRange1.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter
    namedRange1.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter
    namedRange1.BorderAround(, Excel.XlBorderWeight.xlThick, _
        Excel.XlColorIndex.xlColorIndexAutomatic, )
    namedRange1.AutoFormat( _
        Excel.XlRangeAutoFormat.xlRangeAutoFormat3DEffects1, _
        True, False, True, False, True, True)

    If MessageBox.Show("Clear the formatting and notes?", _
        "Test", MessageBoxButtons.YesNo) = DialogResult.Yes Then
        namedRange1.ClearFormats()
        namedRange1.ClearNotes()
    End If
End Sub

Remarks

Cell notes have been replaced by range comments. For more information, see the Comment object.

To add a note that contains more than 255 characters, use this method once to specify the first 255 characters, and then use it again to append the remainder of the note (no more than 255 characters at a time).

Optional Parameters

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

Applies to