NamedRange.Characters Property (2007 System)
Gets a Characters object that represents a range of characters within the text of the NamedRange control.
Namespace: Microsoft.Office.Tools.Excel
Assembly: Microsoft.Office.Tools.Excel.v9.0 (in Microsoft.Office.Tools.Excel.v9.0.dll)
Syntax
'Declaration
<BrowsableAttribute(False)> _
Public ReadOnly Property Characters As NamedRange._CharactersType
'Usage
Dim instance As NamedRange
Dim value As NamedRange._CharactersType
value = instance.Characters
[BrowsableAttribute(false)]
public NamedRange._CharactersType Characters { get; }
[BrowsableAttribute(false)]
public:
property NamedRange._CharactersType^ Characters {
NamedRange._CharactersType^ get ();
}
public function get Characters () : NamedRange._CharactersType
Property Value
Type: Microsoft.Office.Tools.Excel.NamedRange._CharactersType
A Characters object that represents a range of characters within the text of the NamedRange control.
Remarks
The Characters property is intended to be used with the following parameters.
Parameter |
Description |
---|---|
Start |
The first character to be returned. If this argument is either 1 or omitted, this property returns a range of characters starting with the first character. |
Length |
The number of characters to be returned. If this argument is omitted, this property returns the remainder of the string (everything after the Start character). |
If you attempt to use Characters without specifying any parameters, Characters will get a NamedRange._CharactersType object that is part of the Visual Studio Tools for Office infrastructure and is not intended to be used directly from your code.
You can use the Characters object to format characters within a text string. The Characters object is not a collection.
Optional Parameters
For information on optional parameters, see The Variable missing and Optional Parameters in Office Solutions.
Examples
The following code example creates a NamedRange and populates it with the word Smith. It then changes the first character in the word by making it bold and setting the size to 14.
This version is for a document-level customization.
Private charactersRange As Microsoft.Office.Tools.Excel.NamedRange
Private Sub FormatCharacters()
charactersRange = Me.Controls.AddNamedRange( _
Me.Range("A1", "A1"), "charactersRange")
Me.charactersRange.Value2 = "Smith"
Me.charactersRange.Characters(1, 1).Font.Bold = True
Me.charactersRange.Characters(1, 1).Font.Size = 14
End Sub
Microsoft.Office.Tools.Excel.NamedRange charactersRange;
private void FormatCharacters()
{
charactersRange = this.Controls.AddNamedRange(
this.Range["A1", "A1"], "charactersRange");
this.charactersRange.Value2 = "Smith";
this.charactersRange.Characters[1, 1].Font.Bold = true;
this.charactersRange.Characters[1, 1].Font.Size = 14;
}
This version is for an application-level add-in.
Private charactersRange As NamedRange
Private Sub FormatCharacters()
Dim vstoWorksheet As Worksheet = CType( _
Me.Application.ActiveWorkbook.Worksheets(1), _
Excel.Worksheet).GetVstoObject()
charactersRange = vstoWorksheet.Controls.AddNamedRange( _
vstoWorksheet.Range("A1", "A1"), "charactersRange")
Me.charactersRange.Value2 = "Smith"
Me.charactersRange.Characters(1, 1).Font.Bold = True
Me.charactersRange.Characters(1, 1).Font.Size = 14
End Sub
NamedRange charactersRange;
private void FormatCharacters()
{
Worksheet vstoWorksheet = ((Excel.Worksheet)
this.Application.ActiveWorkbook.Worksheets[1]).GetVstoObject();
charactersRange = vstoWorksheet.Controls.AddNamedRange(
vstoWorksheet.Range["A1", "A1"], "charactersRange");
charactersRange.Value2 = "Smith";
charactersRange.Characters[1, 1].Font.Bold = true;
charactersRange.Characters[1, 1].Font.Size = 14;
}
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.
See Also
Reference
Microsoft.Office.Tools.Excel Namespace
Change History
Date |
History |
Reason |
---|---|---|
July 2008 |
Added a version of the code example for an application-level add-in. |
SP1 feature change. |