Text 属性

       

RangeSelection 对象:返回或设置指定区域或所选内容中的文本。String 类型,可读写。

FindReplacement 对象:返回或设置指定区域或所选内容中需要查找或替换的文本。String 类型,可读写。

说明

Text 属性返回选定部分或区域的无格式纯文本。设置该属性,可替换该区域或所选内容的文本。

示例

本示例显示选定区域中的文本。如果没有选中任何内容,则显示插入点之后的字符。

MsgBox Selection.Text

本示例用“Dear”替换活动文档的第一个词。

Set myRange = ActiveDocument.Words(1)
myRange.Text = "Dear "

本示例在新文档中插入 10 行文字。

Documents.Add
For i = 1 To 10
    Selection.Text = "Line" & Str(i) & Chr(13)
    Selection.MoveDown Unit:=wdParagraph, Count:=1
Next i

本示例用“Goodbye”替换活动文档中的“Hello”。

Set myRange = ActiveDocument.Content
With myRange.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "Hello"
    .Replacement.Text = "Goodbye"
    .Execute Replace:=wdReplaceAll
End With