Compartir a través de


DocumentBase.Range (Método)

Devuelve un objeto Microsoft.Office.Interop.Word.Range utilizando las posiciones inicial y final especificadas para el carácter.

Espacio de nombres:  Microsoft.Office.Tools.Word
Ensamblado:  Microsoft.Office.Tools.Word.v4.0.Utilities (en Microsoft.Office.Tools.Word.v4.0.Utilities.dll)

Sintaxis

'Declaración
Public Function Range ( _
    ByRef start As Object, _
    ByRef end As Object _
) As Range
public Range Range(
    ref Object start,
    ref Object end
)

Parámetros

Valor devuelto

Tipo: Microsoft.Office.Interop.Word.Range
Un objeto Microsoft.Office.Interop.Word.Range que utiliza las posiciones inicial y final especificadas del carácter.

Comentarios

Parámetros opcionales

Para obtener información sobre parámetros opcionales, vea Parámetros opcionales en las soluciones de Office.

Ejemplos

En el siguiente ejemplo de código se utiliza el método Range para agregar la cadena "This is a line of text" (Esto es una línea de texto) al documento actual, y después obtiene un objeto Microsoft.Office.Interop.Word.Range que incluye sólo las primeras siete letras de la cadena.Para usar este ejemplo, ejecútelo desde la clase ThisDocument en un proyecto de nivel de documento.

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

Seguridad de .NET Framework

Vea también

Referencia

DocumentBase Clase

Microsoft.Office.Tools.Word (Espacio de nombres)