TextRange 对象

         
多个对象
TextRange
ActionSettings (ActionSetting)
Font
ParagraphFormat
TextRange

包含附加到形状上的文本,以及用于操作文本的属性和方法。

使用 TextRange 对象

本节叙述如何:

返回任意指定形状中的文本范围。

使用 TextFrame 对象的 TextRange 属性返回任意指定形状的 TextRange 对象。使用 Text 属性返回 TextRange 对象中的文本字符串。以下示例向 myDocument 中添加一个矩形并设置其包含的文本。

Set myDocument = ActivePresentation.Slides(1)
myDocument.Shapes.AddShape(msoShapeRectangle, 0, 0, 250, 140) _
    .TextFrame.TextRange.Text = "Here is some test text"

由于 Text 属性是 TextRange 对象的默认属性,以下两条语句等价。

ActivePresentation.Slides(1).Shapes(1).TextFrame _
    .TextRange.Text = "Here is some test text"
ActivePresentation.Slides(1).Shapes(1).TextFrame _
    .TextRange = "Here is some test text"

使用 HasTextFrame 属性可决定形状是否含有文本框,使用 HasText 属性可决定文本框是否包含文本。

返回选定区域中的文本范围。

使用 Selection 对象的 TextRange 属性可返回当前选定的文本。以下示例将选定文本复制到剪贴板。

ActiveWindow.Selection.TextRange.Copy

返回文本范围内的特定字符、单词、行、句子或段落

使用下列方法之一可返回 TextRange 对象中的部分文本:CharactersLinesParagraphsRunsSentencesWords

查找和替换文本范围内的文本

使用 FindReplace 方法可查找和替换文本范围内的文本。

向文本范围中插入文本、日期和时间或幻灯片编号

使用下列方法之一可向 TextRange 对象中插入字符:InsertAfterInsertBeforeInsertDateTimeInsertSlideNumberInsertSymbol