2017-10-04 56 views
0

請我需要你的幫助,我有一個下一個代碼的問題,我想寫在不同的單元格中的所有用戶輸入的值,在Private Sub CommandButton1_Click()我只寫了3個,但我可以'T做,甚至出現了拳頭值,只出現了一個錯誤:循環內的文本框值

object doesn´t support this property or method.

Dim Label1 As Object 
Dim txtB1 As Control 

For NL = 1 To NumeroLineas 
    Set txtB1 = UserForm2.Controls.Add("Forms.TextBox.1", "TxtBx" & NL, True) 

    With txtB1 
     .Name = "TxtBx" & NL 
     .Height = 25.5 
     .Width = 150 
     .Left = 150 
     .Top = 18 * NL * 2 
    End With  
Next NL 
UserForm2.Show 

'This is UserForm2 
Private Sub CommandButton1_Click() 
    Cells(10, 10) = Controls.TxtBx1.Value 
    Cells(10, 11) = Controls.TxtBx2.Value 
    Cells(10, 12) = Controls.TxtBx3.Value 
End sub 
+0

您是關於你的情況下,專家,你知道的一切。請不要以爲其他人也完全瞭解它。 請更具體和詳細:你想達到什麼目標?什麼工作已經?什麼是不正常的?什麼是錯誤信息? – peakpeak

回答

0

您必須解決的代碼生成的控制是這樣的:Controls.Item("ControlName").Value

所以下面應該工作:

Private Sub CommandButton1_Click() 
    Cells(10, 10) = Controls("TxtBx1").Value 
    Cells(10, 11) = Controls("TxtBx2").Value 
    Cells(10, 12) = Controls("TxtBx3").Value 

    'This works too 
    'Cells(10, 10) = Controls.Item("TxtBx1").Value 
End sub 

此外,設置Textbox.Name屬性是多餘的。
此行不是必需的:

.Name = "TxtBx" & NL