循环内的文本框值
问题描述:
请我需要你的帮助,我有一个下一个代码的问题,我想写在不同的单元格中的所有用户输入的值,在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
答
您必须解决的代码生成的控制是这样的: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
您是关于你的情况下,专家,你知道的一切。请不要以为其他人也完全了解它。 请更具体和详细:你想达到什么目标?什么工作已经?什么是不正常的?什么是错误信息? – peakpeak