I did find this snippet and too my surprise a command button was created.
Private Sub cmdJan14_Click() Worksheets("Jan14").Activate Worksheets("Jan14").Range("A1").Select End Sub
However, the subroutine needs to be added so I have that problem. Also, based upon the code above I need to modify specific properties. The properties of a command button would look like these:
Sub CreateButton() Dim Obj As Object Dim Code As String Sheets("Sheet1").Select 'create button Set Obj = ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1", _ Link:=False, DisplayAsIcon:=False, Left:=200, Top:=100, Width:=100, Height:=35) Obj.Name = "TestButton" 'buttonn text ActiveSheet.OLEObjects(1).Object.Caption = "Test Button" 'macro text Code = "Sub ButtonTest_Click()" & vbCrLf Code = Code & "Call Tester" & vbCrLf Code = Code & "End Sub" 'add macro at the end of the sheet module With ActiveWorkbook.VBProject.VBComponents(ActiveSheet.Name).CodeModule .insertlines .CountOfLines + 1, Code End With End Sub
From novice to tech pro — start learning today.