我有一个excel UserForm,可以在执行期间创建文本框。代码如下;
Dim CompHandler() As New CCompHandler
Dim tb As MSForms.TextBox
Dim count As Integer
For i in Range(something)
If i = anotherthing Then
Set tb = UserForm1.Controls.Add("Forms.TextBox.1", "tb" & count)
With tb
.Width = iTbWidth
.Top = count * distance
.Left = iTbLeft
.Height = iTbHeight
.Value = Cells(row, column)
ReDim Preserve CompHandler(0 To count)
Set CompHandler(count).TextBoxGroup = tb
End With
count = count + 1
End If
Next i
我想将更改后的值写回相应的单元格。
我已经能够在框中更改时获得此代码的新值class called CCompHandler
:
Option Explicit
Public WithEvents TextBoxGroup As MSForms.TextBox
Private Sub TextBoxGroup_Change()
MsgBox TextBoxGroup
End Sub
那么..关于如何获得哪个文本框已更改的任何想法? 或者可能有更好的方法吗? 提前致谢
答案 0 :(得分:3)
Tag属性通常用于这样的事情。在创作时添加如下内容:
With tb
...
.Tag = i.Address
...
End With
然后,您可以使用以下内容访问Tag属性:
Debug.Print tbWhoseValueHasChanged.Tag
您的代码段包含许多未定义/不明确的变量,包括i
。我假设它是上面的范围变量。