vba: test if shape contains a textframe

爷,独闯天下 提交于 2019-12-13 02:16:24

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/16171219/vba-test-if-shape-contains-a-textframe

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