多个对象![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
包含附加到形状上的文本,以及用于操作文本的属性和方法。
本节叙述如何:
使用 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 对象中的部分文本:Characters、Lines、Paragraphs、Runs、Sentences 或 Words。
使用 Find 和 Replace 方法可查找和替换文本范围内的文本。
使用下列方法之一可向 TextRange 对象中插入字符:InsertAfter、InsertBefore、InsertDateTime、InsertSlideNumber 或 InsertSymbol。