1.聲明全局變量(不一定全局,但必須要讓第二、
三步能讀取到) Dim WithEvents mycmd As CommandButton
2.controls.add的時候順便把上一步的變量指向它 Set mycmd = Controls.Add("Forms.CommandButton.1", "CommandButton3", Visible)
3.在form1的代碼模塊中(必須在擁有該button的容器模塊),定義事件 Private Sub mycmd_Click()
聯想一下vba的自定義類的自定義事件,在類myclass中定義事件myevent,在類中某處raise myevent,使用時在其它模塊中dim clsMy as new myclass,
然後sub clsMy_myevent就是具體實現事件了。