EXCEL也好,WORD也罢,OFFICE VBA中没有控件数组,VB中有,这是一个差别。
请参以下代码: '* +++++++++++++++++++++++++++++
'* Created By 守柔(ShouRou)@ExcelHome 2005-2-23 4:45:23
'仅测试于System: Windows NT Word: 10.0 Language: 2052
'^The Code CopyIn [类模块-TxtGpTest]^'
'* -----------------------------
Public WithEvents TextBoxGroup As TextBox
Private Sub TextBoxGroup_Change()
MsgBox "TextBoxGroup"
End Sub
'---------------------- '* +++++++++++++++++++++++++++++
'* Created By 守柔(ShouRou)@ExcelHome 2005-2-23 4:46:38
'仅测试于System: Windows NT Word: 10.0 Language: 2052
'^The Code CopyIn [用户窗体-UserForm1]^'
'* -----------------------------
Dim ObjTxt() As New TxtGpTest '定义数组为新类TBxGpTest
Private Sub TextBox1_Change()
MsgBox "This Is TextBox1"
End Sub
'----------------------
Private Sub TextBox2_Change()
MsgBox "This Is TextBox1"
End Sub
'----------------------
Private Sub TextBox3_Change()
MsgBox "This Is TextBox3"
End Sub
'----------------------
Private Sub UserForm_Initialize()
Dim ctl As Control, TxtCount As Integer
For Each ctl In Me.Controls '在窗体控件中循环
If ctl.Name Like "TextBox*" Then '如果为TEXTBOX
TxtCount = TxtCount + 1 '累加
ReDim Preserve ObjTxt(1 To TxtCount) '保存并扩容数组
'将该数组成员事件过程赋于该窗体控件
Set ObjTxt(TxtCount).TextBoxGroup = Me.Controls(ctl.Name)
End If
Next
End Sub
'----------------------
NXrY2QRO.rar
(9.53 KB, 下载次数: 27)
[此贴子已经被作者于2005-2-23 4:50:53编辑过] |