代码:
Option Explicit
Public WithEvents myBttn As MSForms.CommandButton
Public WithEvents myTxt As MSForms.TextBox
Public Sub click(ctl As MSForms.CommandButton)
Set myBttn = ctl
End Sub
Public Sub change(ctl As MSForms.TextBox)
Set myTxt = ctl
End Sub
Private Sub myBttn_Click()
MsgBox "单击我干吗?"
End Sub '
Private Sub myTxt_Change()
MsgBox myTxt.Text
End Sub
窗体部分代码
Option Explicit
Private mTxt(1 To 3) As MyClass
Dim txt As MSForms.TextBox
Private Sub UserForm_Activate()
Dim i As Integer
For i = 1 To UBound(mTxt)
Set txt = Me.Controls.Add("Forms.TextBox.1", "Textbox" &i)
With txt
.Move 10, 10 + (i - 1) * 40, 80, 30
End With
Set mTxt(i) = New MyClass
mTxt(i).change txt
Next
End Sub
窗体中直接赋值:Range("A2").Value = txt1.ValueA2为单元格,txt1为窗体控件
补充:
多个单元格,不同位置也同样的赋值
同工作表:Range("A2").Value = txt1.Value
不同工作表:Range("Sheet2!A3").Value = txt2.Value
数据类型赋值,单元格自动转换成“单元格格式设置”的类型
选中textbox,剪切,然后选中frame(一定要选哦),粘贴。调整textbox在frame中的合适位置即可。-----------------------
请不要把word vba当成VB使用,补充问题即使在VB中运用也存在一定困难。当然在VB中可解决,但基于WORD对象中只怕难实现。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)