shape

シートに挿入されている画像をオブジェクト変数にSetする方法の記録です。

< スポンサーリンク >





インデックス番号「1」の画像をオブジェクト変数にSetし、画像の名前をメッセージで表示する。

Sub test()
    Dim shp As Shape
    Set shp = ActiveSheet.Shapes(1)
    MsgBox shp.Name
End Sub

shape
shape

 

画像の名前「Picture 1」でオブジェクト変数にSetし、画像の名前をメッセージで表示する。

Sub test()
    Dim shp As Shape
    Set shp = ActiveSheet.Shapes(“Picture 1”)
    MsgBox shp.Name
End Sub

shape
shape

 

シートの全ての画像を1つずつSetして、名前をメッセージで表示する。

Sub test()
    Dim shp As Shape
    Dim cnt As Long

    cnt = 1
    For Each shp In ActiveSheet.Shapes
        Set shp = ActiveSheet.Shapes(cnt)
        MsgBox shp.Name
        cnt = cnt + 1
    Next shp
End Sub

shape
shape
shape

< スポンサーリンク >※広告先のお問い合わせは広告主様にお願いします