vba:测试形状是否包含文本框

标签 vba excel shapes

我想遍历 Excel 文件中图表中的所有形状。 这原则上适用于

Dim currChart As Chart
Set currChart = Sheets("Diagramm 1")

Dim sShapes As Shape
For Each sShapes In currChart.Shapes

        Debug.Print sShapes.name
        Debug.Print sShapes.TextFrame.Characters.Text

Next sShapes

但是,TextFrame 属性并非为所有类型的形状所知。因此我想测试一个形状是否有文本框。我该怎么做?

最佳答案

我假设您需要知道形状对象中是否有文本。因此,尝试将此代码放在循环中 For...Next:

Debug.Print sShapes.Name
'to check if there is textframe
'but mostly there is
If Not sShapes.TextFrame Is Nothing Then

    'to check if there is text within textframe
    If sShapes.TextFrame2.HasText Then

        Debug.Print sShapes.TextFrame.Characters.Text
    End If
End If

希望这就是您要找的。

关于vba:测试形状是否包含文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16171219/

相关文章:

excel - 在循环中输入不匹配错误,在列中递增地添加数字

vba - 如何在 PowerPoint 中使用 VBA 自动裁剪图像?

vba - 如何在 Microsoft Excel VBA 中修改合并单元格中的特定文本字符串(更改为粗体)?

c++ - 鼠标单击OpenGL无法围绕其自身中心旋转对象

android - 与 android :drawableBottom attribute. 结合使用时不显示可绘制形状

html - CSS3 eclipse 形状

ms-access - Access VBA 按键

vba - 基于值的慢速宏隐藏行

sql - 将 Excel 电子表格作为表格错误导入 sql

VBA 和 Excel : Why does my TRIM script results in #VALUE on large data sets?