Share via


DocumentBase.Range 方法

使用指定的開始和結束字元位置傳回 Microsoft.Office.Interop.Word.Range

命名空間:  Microsoft.Office.Tools.Word
組件:  Microsoft.Office.Tools.Word.v4.0.Utilities (在 Microsoft.Office.Tools.Word.v4.0.Utilities.dll 中)

語法

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

參數

傳回值

型別:Microsoft.Office.Interop.Word.Range
Microsoft.Office.Interop.Word.Range ,使用指定的開始和結束字元位置。

備註

選擇性參數

如需選擇性參數的詳細資訊,請參閱Office 方案中的選擇性參數

範例

下列程式碼範例會使用 Range 方法,將 "This is a line of text" 字串加入至目前文件,然後取得只包含字串前七個字母的 Microsoft.Office.Interop.Word.Range。 若要使用這個範例,請在文件層級專案中的 ThisDocument 類別執行。

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 安全性

請參閱

參考

DocumentBase 類別

Microsoft.Office.Tools.Word 命名空間