Document.Range 方法 (2007 system)
更新:2007 年 11 月
通过使用指定的起始和结束字符位置来返回 Microsoft.Office.Interop.Word.Range。
命名空间: Microsoft.Office.Tools.Word
程序集: Microsoft.Office.Tools.Word.v9.0(在 Microsoft.Office.Tools.Word.v9.0.dll 中)
语法
声明
Public Function Range ( _
ByRef Start As Object, _
ByRef End As Object _
) As Range
用法
Dim instance As Document
Dim Start As Object
Dim End As Object
Dim returnValue As Range
returnValue = instance.Range(Start, End)
public Range Range(
ref Object Start,
ref Object End
)
参数
Start
类型:System.Object%字符的起始位置。
End
类型:System.Object%字符的结束位置。
返回值
类型:Microsoft.Office.Interop.Word.Range
一个 Microsoft.Office.Interop.Word.Range,使用指定的起始和结束字符位置。
备注
可选参数
有关可选参数的信息,请参见了解 Office 解决方案中的可选参数。
示例
下面的代码示例使用 Range 方法向当前文档添加字符串“This is a line of text”,然后获取一个仅包括该字符串前七个字母的 Microsoft.Office.Interop.Word.Range。
此示例针对的是文档级自定义项。
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);
}
权限
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。