何时在VBA中使用TextFrame或TextFrame2 [英] When to use TextFrame or TextFrame2 in VBA

查看:4400
本文介绍了何时在VBA中使用TextFrame或TextFrame2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Powerpoint中的示例:



TextFrame对象:


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


TextFrame2对象:


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


所以TextFrame2也引用 ShapeRange 对象,它比TextFrame还有一些属性。



我不太确定什么时候或是否应该使用一个或另一个,例如,操纵powerpoint幻灯片上的表格单元格中保留的文本值。两者似乎都工作,并且以下语句返回 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

有什么时候应该使用 TextFrame vs,当我应该使用 TextFrame2 autoshapes-with-vba /rel =nofollow noreferrer> http://peltiertech.com/programming-excel-2007-2010-autoshapes-with-vba/



TextFrame2成员被添加到Excel 2007中,并且更好地控制了文本的格式,因为它不是向后兼容的,我建议使用TextFrame对象



我猜也是这样在PPT中适用。


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?

解决方案

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.

这篇关于何时在VBA中使用TextFrame或TextFrame2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆