何时在 VBA 中使用 TextFrame 或 TextFrame2

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16674028/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 21:13:35  来源:igfitidea点击:

When to use TextFrame or TextFrame2 in VBA

vbaexcel-vbapowerpoint-vbaexcel

提问by David Zemens

Example, in Powerpoint:

示例,在 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.

表示 Shape 对象中的文本框架。包含文本框架中的文本以及控制文本框架对齐和定位的属性和方法。

The TextFrame2 object:

TextFrame2 对象:

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.

表示 Shape 或 ShapeRange 对象中的文本框架。包含文本框架中的文本并公开控制文本框架对齐和定位的属性和方法。

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

所以TextFrame2也是指ShapeRange对象,比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.

例如,我不确定何时或是否应该使用其中一种来操作幻灯片上表格单元格中的文本值。两者似乎都有效,以下语句返回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 TextFramevs when I should use TextFrame2?

是否有关于何时应该使用TextFrame与何时应该使用的明确指南TextFrame2

回答by Tim Williams

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

根据 Jon Peltier 的说法: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"

“在 Excel 2007 中添加了 TextFrame2 成员,可以更好地控制文本的格式。因为它不向后兼容,我建议使用 TextFrame 对象”

I'm guessing a similar situation applies in PPT.

我猜类似的情况也适用于 PPT。