TextRange Interface

Contains the text that's attached to a shape, and properties and methods for manipulating the text.

Namespace:  Microsoft.Office.Interop.PowerPoint
Assembly:  Microsoft.Office.Interop.PowerPoint (in Microsoft.Office.Interop.PowerPoint.dll)

Syntax

'Declaration
<GuidAttribute("9149348F-5A91-11CF-8700-00AA0060263B")> _
Public Interface TextRange _
    Inherits Collection
'Usage
Dim instance As TextRange
[GuidAttribute("9149348F-5A91-11CF-8700-00AA0060263B")]
public interface TextRange : Collection

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.

Examples

Use the TextRange property of the TextFrame object to return a TextRange object for any shape you specify. Use the Text property 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"

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"

Use the HasTextFrame property to determine whether a shape has a text frame, and use the HasTextFrame property to determine whether the text frame contains text.

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

Use one of the following methods to return a portion of the text of a TextRange object: [Characters#SameCHM] , [Lines#SameCHM] , [Paragraphs#SameCHM] , [Runs#SameCHM] , [Sentences#SameCHM] , or [Words#SameCHM] .

Use the FindByName(Object) and Replace(String, String, Int32, MsoTriState, MsoTriState) methods to find and replace text in a text range.

Use one of the following methods to insert characters into a TextRange object: InsertAfter(String) , InsertBefore(String) , InsertDateTime(PpDateTimeFormat, MsoTriState) , InsertSlideNumber() , or InsertSymbol(String, Int32, MsoTriState) .

See Also

Reference

TextRange Members

Microsoft.Office.Interop.PowerPoint Namespace