Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use TextFrame or TextFrame2 in VBA

Example, in Powerpoint:

The TextFrame object:

Represents the text frame in a Shape object. Contains the text in the text frame and the properties and methods that control the alignment and anchoring of the text frame.

The TextFrame2 object:

Represents the text frame in a Shape or ShapeRange object. Contains the text in the text frame and exposes properties and methods that control the alignment and anchoring of the text frame.

So TextFrame2 also refers to ShapeRange object, and it has a few more properties than TextFrame.

I am not really sure when or whether I should use one or the other, for example, to manipulate the text values held in Table cells on a powerpoint slide. Both seem to work, and the following statement returns TRUE.

Dim tbl as Table
Set tbl = ActivePresentation.Slides(1).Shapes("Table1").Table

tbl.Cell(r, c).Shape.TextFrame2.TextRange.Characters.Text = _
    tbl.Cell(r, c).Shape.TextFrame.TextRange.Characters.Text

Is there some definitive guide on when I should use TextFrame vs when I should use TextFrame2?

like image 769
David Zemens Avatar asked May 21 '13 15:05

David Zemens


2 Answers

According to Jon Peltier here: http://peltiertech.com/programming-excel-2007-2010-autoshapes-with-vba/

"The TextFrame2 member was added in Excel 2007 and gives better control over the formatting of the text. Because it is not backward compatible, I would recommend using the TextFrame object"

I'm guessing a similar situation applies in PPT.

like image 130
Tim Williams Avatar answered Sep 18 '22 12:09

Tim Williams


In addition, TextFrame doesn't contain the property LanguageID in macOS, so you're forced to use TextFrame2. Be aware of that if you're working with that property in a cross-platform environment. I faced that problem in the past.

like image 25
kalamarin Avatar answered Sep 19 '22 12:09

kalamarin