Freigeben über


DocumentBase.Range(Object, Object) Method

Definition

Returns a Range by using the specified starting and ending character positions.

public Microsoft.Office.Interop.Word.Range Range (ref object start, ref object end);
member this.Range : obj * obj -> Microsoft.Office.Interop.Word.Range
Public Function Range (Optional ByRef start As Object, Optional ByRef end As Object) As Range

Parameters

start
Object

The starting character position.

end
Object

The ending character position.

Returns

A Range that uses the specified starting and ending character positions.

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 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);
}
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

Remarks

Optional Parameters

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

Applies to