次のコードを使用して、VBA で ActiveX コマンド ボタンの name プロパティを変更しようとしています。
Set shp = ActiveSheet.Shapes(Selection.Name)
With shp.OLEFormat.Object
.Object.Caption = "Node" & Str(NumNodes)
.Name = "Node" & Str(NumNodes)
End With
キャプション名は変更できますが、上記のコードでは name プロパティを変更できません。name プロパティの文字列を int (NumNodes) と連結する方法を見つける必要があります。
アップデート
これは、コマンド ボタンをコピーして特定のセル位置に貼り付ける完全なサブルーチンです。ボタンの作成時に、名前やキャプションなどのプロパティも変更されます。
Public Sub Node_Button_Duplication()
'
'Comments: Copies and pastes Node 1's button to the appropriate column
Dim shp As Shape
' Copy Node 1 button and paste in appropriate location
ActiveSheet.Shapes("CommandButton1").Select
Selection.Copy
Cells(5, 10 + 7 * (NumNodes - 1) - 1).Select
ActiveSheet.Paste
Selection.ShapeRange.IncrementLeft 47.25
Selection.ShapeRange.IncrementTop -13.5
Set shp = ActiveSheet.Shapes(Selection.Name)
With shp.OLEFormat.Object
.Object.Caption = "Node" & Str(NumNodes)
.Name = "Node" & Str(NumNodes)
End With
End Sub