TextRange 对象(PowerPoint)TextRange object (PowerPoint)

包含附加到形状的文本,以及用于操作文本的属性和方法。Contains the text that's attached to a shape, and properties and methods for manipulating the text.

备注Remarks

以下示例说明如何执行下列操作:The following examples describe how to:

  • 返回任意指定形状中的文本范围。Return the text range in any shape you specify.

  • 返回选定范围中的文本范围。Return a text range from the selection.

  • 返回文本范围中的特定字符、单词、行、句子或段落。Return particular characters, words, lines, sentences, or paragraphs from a text range.

  • 查找和替换文本范围内的文本。Find and replace text in a text range.

  • 向文本范围中插入文本、日期和时间或幻灯片编号。Insert text, the date and time, or the slide number into a text range.

  • 将光标定位到文本范围内所需的任意位置。Position the cursor wherever you want in a text range.

示例Example

使用**TextFrame** 对象的textrange属性可返回您指定的任何形状的textrange对象。Use the TextRangeproperty of the TextFrame object to return a TextRange object for any shape you specify. 使用Text属性返回TextRange对象中的文本字符串。Use the Textproperty to return the string of text in the TextRange object. 以下示例向 myDocument 中添加一个矩形并设置其包含的文本。The following example adds a rectangle to myDocument and sets the text it contains.

Set myDocument = ActivePresentation.Slides(1)

myDocument.Shapes.AddShape(msoShapeRectangle, 0, 0, 250, 140) _

    .TextFrame.TextRange.Text = "Here is some test text"

由于Text属性是TextRange对象的默认属性,因此以下两个语句是等效的。Because the Text property is the default property of the TextRange object, the following two statements are equivalent.

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属性 属性可确定文本框架中是否包含文本。Use the HasTextFrameproperty to determine whether a shape has a text frame, and use the HasTextproperty to determine whether the text frame contains text.

使用Selection对象的TextRange属性可返回当前选定的文本。Use the TextRange property of the Selection object to return the currently selected text. 下面的示例将选定内容复制到剪贴板。The following example copies the selection to the Clipboard.

ActiveWindow.Selection.TextRange.Copy

使用下列方法之一来返回 TextRange 对象的文本的某个部分︰ 字符 的段落 运行 的句子 或多个 单词.Use one of the following methods to return a portion of the text of a TextRange object: Characters, Lines, Paragraphs, Runs, Sentences, or Words.

使用查找替换若要查找和替换文本范围内的文本的方法。Use the Findand Replacemethods to find and replace text in a text range.

使用下列方法之一将字符插入 TextRange 对象︰新段落活动InsertDateTimeInsertSlideNumberInsertSymbol.Use one of the following methods to insert characters into a TextRange object:InsertAfter, InsertBefore, InsertDateTime, InsertSlideNumber, or InsertSymbol.

方法Methods

名称Name
AddPeriodsAddPeriods
ChangeCaseChangeCase
CharactersCharacters
CopyCopy
CutCut
删除Delete
FindFind
InsertAfterInsertAfter
InsertBeforeInsertBefore
InsertDateTimeInsertDateTime
InsertSlideNumberInsertSlideNumber
InsertSymbolInsertSymbol
线条Lines
LtrRunLtrRun
ParagraphsParagraphs
PastePaste
PasteSpecialPasteSpecial
RemovePeriodsRemovePeriods
ReplaceReplace
RotatedBoundsRotatedBounds
RtlRunRtlRun
运行Runs
SelectSelect
SentencesSentences
TrimTextTrimText
WordsWords

属性Properties

名称Name
ActionSettingsActionSettings
应用程序Application
BoundHeightBoundHeight
BoundLeftBoundLeft
BoundTopBoundTop
BoundWidthBoundWidth
CountCount
FontFont
IndentLevelIndentLevel
LanguageIDLanguageID
长度Length
ParagraphFormatParagraphFormat
ParentParent
StartStart
TextText

另请参阅See also

PowerPoint 对象模型引用PowerPoint Object Model Reference

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.