Udostępnij za pośrednictwem


DocumentBase.Range Method

Returns a Microsoft.Office.Interop.Word.Range by using the specified starting and ending character positions.

Namespace:  Microsoft.Office.Tools.Word
Assembly:  Microsoft.Office.Tools.Word.v4.0.Utilities (in Microsoft.Office.Tools.Word.v4.0.Utilities.dll)

Syntax

'Declaration
Public Function Range ( _
    ByRef start As Object, _
    ByRef end As Object _
) As Range
public Range Range(
    ref Object start,
    ref Object end
)

Parameters

Return Value

Type: Microsoft.Office.Interop.Word.Range
A Microsoft.Office.Interop.Word.Range that uses the specified starting and ending character positions.

Remarks

Optional Parameters

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

Examples

The following code example uses the Range method to add the string "This is a line of text" to the current document, and then gets a Microsoft.Office.Interop.Word.Range that includes only the first seven letters of the string. To use this example, run it from the ThisDocument class in a document-level project.

Private Sub DocumentRange()
    Me.Range(0, 0).Text = "This is a line of text. "

    ' Display only the first seven characters in the string.
    Dim range2 As Word.Range = Me.Range(0, 7)
    MessageBox.Show(range2.Text)
End Sub
private void DocumentRange()
{
    // Add a string to the document.
    object start = 0;
    object end = 0;
    string newText = "This is a line of text. ";
    Word.Range range1 = this.Range(ref start, ref end);
    range1.Text = newText;

    // Display only the first seven characters in the string.
    end = 7;
    Word.Range range2 = this.Range(ref start, ref end);
    MessageBox.Show("The first seven characters: " +
        range2.Text);
}

.NET Framework Security

See Also

Reference

DocumentBase Class

Microsoft.Office.Tools.Word Namespace