'--------------------------------------------------
'プロシージャの概要:
'処理名:getShapeCaption
'概要:シェイプからキャプション(表示文字)を取得
'shp:対象シェイプ
'[戻り値]:キャプション文字列
'--------------------------------------------------
Private Function getShapeCaption(shp As Excel.Shape) As String
Dim strCaption As String
On Error GoTo ErrorHandler
' TextFrame2.TextRange.Textを優先して取得
If shp.HasTextFrame Then
If shp.TextFrame2.HasText Then
strCaption = shp.TextFrame2.TextRange.Text
GoTo ExitFunction
End If
End If
' TextFrame.Characters.Textを試行
If shp.HasTextFrame Then
strCaption = shp.TextFrame.Characters.Text
GoTo ExitFunction
End If
' Captionプロパティを試行
strCaption = shp.Caption
GoTo ExitFunction
' Textプロパティを試行
strCaption = shp.Text
GoTo ExitFunction
ErrorHandler:
' エラー時の処理
Select Case Err.Number
Case 438 ' オブジェクトは、このプロパティまたはメソッドをサポートしていません
Resume Next
Case -2147024809 ' パラメータが間違っています
Resume Next
Case Else
' その他のエラーは「テキストなし」として処理
strCaption = "テキストなし"
GoTo ExitFunction
End Select
ExitFunction:
If strCaption = "" Then
strCaption = "テキストなし"
End If
getShapeCaption = strCaption
End Function