Working with Text in a Shape

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

Much of what you do with shapes on slides involves adding or modifying text. In addition to the Textbox shape, many other Shape objects can contain text. For example, you can add text to many of the AutoShape Shape objects.

All shapes that support text have a TextFrame property you can use to return a TextFrame object. You can determine if a shape supports the use of a text frame by using the Shape object's HasTextFrame property. Each TextFrame object has a HasText property you can use to determine if the text frame contains text.

The TextFrame object has a TextRange property you use to return a TextRange object. You use the TextFrame object's Text property to specify or determine the text within a frame. You use the properties and methods of the TextRange object to work with the text associated with a Microsoft® PowerPoint® shape.

Note   Placeholder shapes contain default text that is visible from the PowerPoint user interface, but is not available programmatically. When you set the Text property of a Placeholder shape's TextRange object, the default text is replaced with the text you specify.

There is one Shape object that contains text but does not use the TextFrame or TextRange objects. The TextEffect property returns a TextEffectFormat object that contains the properties and methods used to work with WordArt shapes. You add WordArt shapes to a slide by using the Shapes collection's AddTextEffect method. The text of the WordArt shape and the location of the shape are specified in the arguments to the AddTextEffect method. You use the TextEffectFormat object's Text property to read or change the text in a WordArt shape. For example, the following code changes the text of an existing WordArt shape on the first slide of the current presentation:

With ActivePresentation
   strExistingText =    .Slides(1).TextEffect.Text
   If Len(strNewText) <= Len(strExistingText) Then
      .Slides(1).TextEffect.Text = strNewText
   End If
End With

Note that this code checks to make sure the new text is not longer than the existing text. This step is required because a WordArt shape does not automatically resize itself to accommodate new text. Alternatively, you could capture the properties of the existing WordArt shape, then delete it and replace it with a new WordArt shape that uses the same properties as the old shape.

See Also

Working with Shapes on Slides | Adding Shapes to Slides | Positioning Shapes on Slides