adding a routine/event to a control during execution

Hi to all,

I'm writing a macro in Excel, and just added a commandbutton to a form during its execution, but i'm not able to assign an execution code/routine to it! i've tryed the help on line and haven't found anything usefull, may you help me?

This is the code i wrote:

Private Sub UserForm_Initialize()
Dim CButton As Control
Dim X, Y

X=8
Y=16

Set CButton = frmDiametri_e_Spessori.Controls.Add("Forms.CommandButton.1")
CButton.Left = X
CButton.Top = Y
CButton.Caption = "OK"

End sub

Now i want to add some code to the CButton control so that, when clicked, it apply the changes i've done in the form

Thanks

Pierpaolo

[812 byte] By [Pierpaolo] at [2007-12-24]
# 1
Put your button togheter with the code at design time, setting the visible property to false. At runtime you change the design attributes and finally make the button visible.
Uwe_Neufeld at 2007-8-31 > top of Msdn Tech,Microsoft ISV Community Center Forums,Visual Basic for Applications (VBA)...