VBA object added in a form

Hi to all,

I've added a commandbutton to a form during its execution, but i'm not able to assign an execution code 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:

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

Now i want to add some code to the CButton control

Thanks

Pierpaolo

[536 byte] By [Pierpaolo] at [2007-12-24]
# 1
AddHandler CButton.Click , AddressOf <Function Name>
PrasantSwain at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 2
I've tryied but the VBA (for excell) doesn't recognize the AddHandler method
Pierpaolo at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 3
You

can't reference ActiveX objects directly like this in a .NET

application. At a minimum, you need to let the IDE create a COM

callable wrapper by setting a COM reference to the VBA Forms component.

Before we head down that perilous path, why are you doing this?

Windows Forms has its own Button control and it is fully supported by

the designer...

nobugz at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 4

thanks for the reply...
i've also noticed that this isn't the right forum and i've reposted the question in the VBA forum, anyway:

I've a macro in excel that ask the user for some inputs. i store these input in an array. The number of inputs may vary.
After i initialize the main form, in which i've putted a commandbutton to call another form to show me these inputs by using some textbox. So i've tryied to
make a form that have the right number of textbox. i've done this and put in the new form a button. But when i want to click the button to close the form i've
noticed that i'm uanble to associate any routine to the button!

I hope to have been clearly
I'll apreciate any answer

Thanks
Pierpaolo

Pierpaolo at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...