我有一个在执行期间创建文本框的 excel 用户窗体。 代码如下;
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
那么..关于如何获取哪个文本框已更改的任何想法?或者也许有更好的方法可以做到这一点?提前致谢
Tag 属性通常用于类似的东西。 创建时添加以下内容:
With tb
...
.Tag = i.Address
...
End With
然后,您可以稍后访问 Tag 属性,如下所示:
Debug.Print tbWhoseValueHasChanged.Tag
您的代码片段有很多未定义/不清楚的变量,包括i
. 我假设它是上面的范围变量。