Hi,
I am having difficulty adding code to a commandbutton and wondered if anyone has a solution for how to do this.
Brief description:
I create a worksheet on an open workbook by code (from a remote xla). I add a button to that worksheet by code. I want to assign event code to that button, but the .OnAction command doesn't work.
'**********************************
Sub AddSheet()
Worksheets.Add
ActiveSheet.Name = "NewSheet"
'Add OLE commandbutton
Range("O1"
.Select
ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1", Link:=False _
, DisplayAsIcon:=False, Left:=348.75, Top:=12, Width:=72, Height:=24) _
.Select
Selection.ShapeRange.IncrementLeft -5.25
Selection.ShapeRange.IncrementTop -9.75
Selection.Name = "cmdMoveValue"
'Selection.Caption = "Move Value"
'Copy activation code to worksheet
ActiveSheet.OLEObjects("cmdMoveValue"
.OnAction "MoveValue"
Range("B4"
.Select
End Sub
'**********************************
Sub MoveValue()
msgbox "The button works!", vbokonly, "Yahoo!"
End Sub
I am having difficulty adding code to a commandbutton and wondered if anyone has a solution for how to do this.
Brief description:
I create a worksheet on an open workbook by code (from a remote xla). I add a button to that worksheet by code. I want to assign event code to that button, but the .OnAction command doesn't work.
'**********************************
Sub AddSheet()
Worksheets.Add
ActiveSheet.Name = "NewSheet"
'Add OLE commandbutton
Range("O1"
ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1", Link:=False _
, DisplayAsIcon:=False, Left:=348.75, Top:=12, Width:=72, Height:=24) _
.Select
Selection.ShapeRange.IncrementLeft -5.25
Selection.ShapeRange.IncrementTop -9.75
Selection.Name = "cmdMoveValue"
'Selection.Caption = "Move Value"
'Copy activation code to worksheet
ActiveSheet.OLEObjects("cmdMoveValue"
Range("B4"
End Sub
'**********************************
Sub MoveValue()
msgbox "The button works!", vbokonly, "Yahoo!"
End Sub