When to use TextFrame or TextFrame2 in VBA

霸气de小男生 提交于 2019-12-21 03:29:08

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/16674028/when-to-use-textframe-or-textframe2-in-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!