- 帖子
- 605
- 主題
- 92
- 精華
- 0
- 積分
- 648
- 點名
- 0
- 作業系統
- windows
- 軟體版本
- 7
- 閱讀權限
- 50
- 性別
- 男
- 來自
- macau
- 註冊時間
- 2013-4-5
- 最後登錄
- 2019-2-10
 
|
3#
發表於 2013-6-1 00:13
| 只看該作者
本帖最後由 sunnyso 於 2013-6-1 00:19 編輯
回復 1# pinklee - Dim AllBtn() As New Class1
- Private Sub UserForm_Initialize()
- Dim fcb As MSForms.CommandButton
- Dim fcbNum As Integer
- fcbWidth = 30
- fcbNum = 5 'Sheets("總表").Range("A1").Value
- ReDim AllBtn(1 To fcbNum)
- For ii = 1 To fcbNum
- Set fcb = UserForm1.Controls.Add("Forms.CommandButton.1", "CommandButton" & ii, True)
- Set AllBtn(ii).Btn = fcb
- fcb.Width = fcbWidth
- fcb.Left = (ii - 1) * fcbWidth
- fcb.Caption = "C" & ii
- Next
- End Sub
複製代碼 物件類別模組- Public WithEvents Btn As MSForms.CommandButton
- Private Sub Btn_Click()
- 'Dim ctrl As Control
- 'With UserForm1
- 'your code here
- MsgBox Btn.Caption
- 'End With
- End Sub
複製代碼 |
|