返回列表 上一主題 發帖

[發問] 跨UserForm執行CommandButton

回復 1# boyao
有沒有較簡單的指令寫法?或者只能重新在UserForm2重設相同指令?
要有範例內容,才知有解無解.

TOP

回復 3# boyao
使用物件類別模組 試試看
在VBA中插入物件類別模組, 預設名稱為 Class1.
UserForm的程式碼
  1. Dim User_按鈕 As New Class1    'UserForm 宣告 變數為新的物件類別模組
  2. Private Sub UserForm_Initialize()
  3.     Set User_按鈕.物件_CommandButton = CommandButton1
  4.     '新的物件類別模組 變數( 物件_CommandButton )= 設定 為 CommandButton1
  5. End Sub
複製代碼
物件類別模組的程式碼
  1. Option Explicit
  2. Public WithEvents 物件_CommandButton As MSForms.CommandButton
  3. Private Sub 物件_CommandButton_Click()
  4.     Dim i As Integer
  5.     For i = 1 To 100
  6.         Sheet1.Range("A" & i) = (i * 50)
  7.     Next i '
  8. End Sub
複製代碼

TOP

        靜思自在 : 為自己找藉口的人永遠不會進步。
返回列表 上一主題