'新しいシートを挿入
Sub New_Sheet()
Dim NewWorkSheet As Worksheet
Dim Sheet_Name As String
Sheet_Name = InputBox("シート名を入力")
Set NewWorkSheet = Worksheets.Add()
NewWorkSheet.Name = Sheet_Name
Call InsertButtonOnSheet(NewWorkSheet)
End Sub
'ボタンを作る
Sub InsertButtonOnSheet(Insert_Sheet As Worksheet)
Dim ws As Worksheet: Set ws = Insert_Sheet '作るシートを引数で受け取る
Dim obj As Object
'B2からC3の範囲でボタンを作成
Set obj = ws.Buttons.Add(Range("B2").Left, _
Range("B2").Top, _
Range("B2:C3").Width, _
Range("B2:C3").Height)
With obj
.Characters.Text = "Test Button" 'ボタン表示テキスト
.OnAction = "Msg_Open" '登録マクロ名
End With
End Sub
'登録用サンプルマクロ
Sub Msg_Open()
MsgBox ("こんにちは")
End Sub