標題:
[發問]
關於 UserForm1.Controls.Add "Forms.CommandButton.1" 問題請教
[打印本頁]
作者:
pinklee
時間:
2013-5-31 16:24
標題:
關於 UserForm1.Controls.Add "Forms.CommandButton.1" 問題請教
ii = Sheets("sheet2").Range("m1").Value
For ii = 1 To ii
UserForm1.Controls.Add "Forms.CommandButton.1", "CommandButton" & ii, True
Next
以上執行結果如下圖
[attach]15120[/attach]
請教各位先拜 如何按 各個 CommandButton 執行巨集呢?
是否要用到 物件特別模組 有勞大大囉 謝謝!!
作者:
sunnyso
時間:
2013-5-31 23:08
回復
1#
pinklee
Private Sub UserForm_Initialize()
Dim fcb As MSForms.CommandButton
fcbWidth = 30
fcbNum = 5
For ii = 1 To fcbNum
Set fcb = UserForm1.Controls.Add("Forms.CommandButton.1", "CommandButton" & ii, True)
fcb.Width = fcbWidth
fcb.Left = (ii - 1) * fcbWidth
fcb.Caption = "C" & ii
Next
End Sub
複製代碼
作者:
sunnyso
時間:
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
複製代碼
作者:
pinklee
時間:
2013-6-3 08:04
回復
3#
sunnyso
感謝您的指導 我先研究一下
作者:
pinklee
時間:
2013-6-3 09:57
回復
3#
sunnyso
感謝您 已經可以使用
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)