2013-04-23 48 views
1

我想循環顯示excel文件中圖表中的所有形狀。 這工作原則與vba:測試形狀是否包含文本框

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並非所有類型的形狀而聞名。因此我想測試一個形狀是否有文本框。我怎樣才能做到這一點?

回答

3

我認爲你需要知道你的形狀對象中是否有文字。因此,儘量把你的循環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 

我希望這是你在找什麼。

+0

好一個+ 1 :) – 2013-04-24 11:55:28

相關問題