我想遍历 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/