Creating buttons using VBA
Just to add another:
Recording a macro is pretty useful in this case -
ActiveSheet.OLEObjects.Add(ClassType:="Forms.Comma ndButton.1", _
Link:=False, _
DisplayAsIcon:=False, _
Left:=144.75, _
Top:=88.5, _
Width:=71.25,
Height:=18).Select
You can drop the select
Sub Macro2()
Dim cmbButton As MSForms.CommandButton
Dim oButton As OLEObject
Set oButton = _
ActiveSheet.OLEObjects.Add(ClassType:="Forms.Comma ndButton.1", _
Link:=False, _
DisplayAsIcon:=False, _
Left:=144.75, _
Top:=88.5, _
Width:=71.25, _
Height:=18)
oButton.Top = 0
Set cmbButton = oButton.Object
cmbButton.Caption = "MyButton"
End Sub
You could set the top property in the ADD method. I have left it as
recorded and then moved the button just to illustrate. The Top property is
an attribute of the OleObject container. The commandbutton itself is the
OleObject.Object (thus my use of two variables).
--
Regards,
Tom Ogilvy
"CT" wrote in message
nk.net...
I am trying to create a button and put it onto a spreadsheet using VBA.
Dim cmdButton As Object
Set cmdButton = CreateObject("Forms.CommandButton.1")
cmdButton.Top = 0
Run time error 438;
Object: doesn't support this property or method
Occurs on cmdButton.Top = 0
I am trying to set the position of the top of the new command button.
Where am I going wrong?
Thanks,
Tim
|