vba:测试shape是否包含文本框 [英] vba: test if shape contains a textframe

查看:1115
本文介绍了vba:测试shape是否包含文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在excel文件中的图表中循环所有形状。
这原则上与

  Dim currChart As Chart 
设置currChart = Sheets(Diagramm 1 )

Dim sShapes As Shape
对于每个sShapes在currChart.Shapes

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

下一个sShapes

但是,属性 TextFrame 不是所有类型的形状都知道的。因此,我想测试一个形状是否有一个文本框。我如何做?

解决方案

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

  Debug.Print sShapes.Name 
'来检查是否有文本框$​​ b $ b'但主要是
如果不是sShapes.TextFrame是没有

'检查文本框内是否有文本
如果sShapes.TextFrame2.HasText然后

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

我希望这是你正在寻找的。


I want to loop over all shapes in a chart in an excel file. This works in principle with

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

However, the property TextFrame is not known by all type of shapes. therefore I want to test if a shape has a textframe. How can I do that?

解决方案

I assumed that you need to know if there is text within your shape object. Therefore try to put this code within your loop 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

I hope it is what you are looking for.

这篇关于vba:测试shape是否包含文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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