How to Insert a Command Button
Change the Properties of Command Button
Private Sub CommandButton1_Click()
CommandButton1.Caption = "Sriguranjani"
CommandButton1.Height = 75
CommandButton1.Width = 210
CommandButton1.BackColor = RGB(255, 255, 0)
CommandButton1.ForeColor = RGB(255, 0, 0)
CommandButton1.Font = "Hobo Std"
CommandButton1.Font.Size = 35
End Sub
Insert a Command Button Programatically
Sub Edit_properties_of_cmdbutton()
Dim cmdbut As OLEObject
On Error Resume Next
Set cmdbut = ActiveSheet.OLEObjects.Add _
(ClassType:="Forms.CommandButton.1", Link:=False _
, DisplayAsIcon:=False, Left:=150, Top:=14)
cmdbut.Object.Caption = "Sriguranjani"
cmdbut.Height = 55
cmdbut.Width = 125
cmdbut.Object.Font.Name = "Hobo Std"
cmdbut.Object.Font.Size = 21
cmdbut.Object.BackColor = RGB(0, 0, 225)
'cmdbut.Object.BackColor = RGB(0, 225, 0)
cmdbut.Object.ForeColor = RGB(0, 225, 0)
End Sub
Create command Button in New Workbook
Private Sub CommandButton1_Click()
Dim wkb As Workbook
Set wkb = Workbooks.Add
wkb.Sheets(2).Activate
Dim cmdbut As OLEObject
On Error Resume Next
Set cmdbut = ActiveSheet.OLEObjects.Add _
(ClassType:="Forms.CommandButton.1", Link:=False _
, DisplayAsIcon:=False, Left:=450, Top:=101)
cmdbut.Height = 35
cmdbut.Width = 455
cmdbut.Object.Font.Name = "Calisto MT"
cmdbut.Object.Font.Size = 21
cmdbut.Object.BackColor = RGB(0, 0, 225)
'cmdbut.Object.BackColor = RGB(225, 0, 0)
'cmdbut.Object.BackColor = RGB(0, 225, 0)
cmdbut.Object.ForeColor = RGB(0, 225, 0)
ActiveSheet.CommandButton1.Caption = "I am new Command Button"
MsgBox "new command button has been created"
End Sub
Program to edit the Properties of COMMAND BUTTON