I would like to create a macro within a UserForm that would create a CommandButton with a certain caption and assigns an OnClick event to it. I cannot figure out how to assign the macro . It should look like something like this. I would appreciate any ideas how to go about this.
Private Result as String
-----------------------------
Sub VytvorForumular()
Dim NewButton As OLEObject
Set CmdBtn = ButtonForm.Controls.Add("Forms.CommandButton.1")
With CmdBtn
.Caption = "Value1"
.onclick = SaveSelInVariable(.Caption) 'This is the part I cannot figure out - I just made this syntax up
End With
end sub
---------------------------
Sub SaveSelInVariable (SelValue as String)
Result = SelValue
end sub
Bookmarks