Table of contents
TOC
折叠目录
展开目录

TextRange 对象 (PowerPoint)TextRange Object (PowerPoint)

office 365 dev account|上次更新日期: 2018/3/13
|
2 参与人员

包含附加到形状的文本,以及用于操作文本的属性和方法。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对象。使用Text属性返回TextRange对象中的文本字符串。下面的示例添加一个矩形myDocument,并设置其包含的文本。Use the TextRangeproperty of the TextFrame object to return a TextRange object for any shape you specify. Use theTextproperty to return the string of text in the TextRange object. 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对象:新段落活动InsertDateTimeInsertSlideNumberInsertSymbolUse 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
DeleteDelete
FindFind
新段落InsertAfter
活动InsertBefore
InsertDateTimeInsertDateTime
InsertSlideNumberInsertSlideNumber
InsertSymbolInsertSymbol
线条Lines
LtrRunLtrRun
ParagraphsParagraphs
PastePaste
PasteSpecialPasteSpecial
RemovePeriodsRemovePeriods
ReplaceReplace
RotatedBoundsRotatedBounds
RtlRunRtlRun
运行Runs
SelectSelect
SentencesSentences
TrimTextTrimText
WordsWords

属性Properties

名称Name
ActionSettingsActionSettings
ApplicationApplication
BoundHeightBoundHeight
BoundLeftBoundLeft
BoundTopBoundTop
BoundWidthBoundWidth
CountCount
FontFont
IndentLevelIndentLevel
语言标识LanguageID
长度Length
ParagraphFormatParagraphFormat
ParentParent
StartStart
TextText

另请参阅See also

其他资源Other resources

PowerPoint 对象模型引用PowerPoint Object Model Reference

© 2018 Microsoft