返回列表 上一主題 發帖

[發問] 動態新增 UserForm 及 CommandButton 後 如何寫click的動作?

我的問題比較簡單一點,程式的目的是在既有的表單(UserForm3),新增3個TextBox,然後每個TextBox可以執行function(y_m_dinput (A),變數為A),程式碼如下:
For X2 = 1 To 3
Set theTextBox = UserForm3("frame1").Controls.Add("Forms.TextBox.1", "TextBox" & TeCount + X2, True)
  With theTextBox
     .Name = "TextBox" & TeCount + X2
     If X2 = 1 Then
     .Left = 210
     ElseIf X2 = 2 Then
     .Left = 384
     Else
      .Left = 492
     End If
     .Width = 60
     .Top = K2 + 18
    myName = "Userform3"
    With ThisWorkbook.VBProject.VBComponents(myName).CodeModule
     '.DeleteLines 1, .countoflines
      Test = .countoflines - 44
     .insertlines Test, "Private Sub TextBox" & TeCount + X2 & "_Change()"
     .insertlines Test + 1, "A =" & TeCount + X2
     .insertlines Test + 2, "y_m_dinput (A)"
     .insertlines Test + 3, "End sub"
    End With
  End With
Next X2
程式的結果可以跑出3個TextBox,也可以寫了出相對應的程序,但是就是無法執行function.
請問問題出在哪??

TOP

        靜思自在 : 我們最大的敵人不是別人.可能是自己。
返回列表 上一主題