求助:如何实现VBA中textbox控件的自动生成?

Rita0120 2005-09-19 02:44:33
我要实现textbox和checkbox的自动生成。也就是当在textbox中添加内容
完毕后,回车就能再生成一个textbox。
...全文
412 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
myhgyp 2005-09-19
  • 打赏
  • 举报
回复
Dim btnObj As Control
Public Sub NewTextBox(ByVal CtrlName As String)
Set btnObj = Me.Controls.Add("Forms.TextBox.1", "TextBoxName")
With btnObj
.Text = Text1.Text
.Top = 100
.Left = 100
.Visible = True
End With
End Sub


Private Sub Text1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 13 Then NewTextBox TxtCtrl
End Sub
myhgyp 2005-09-19
  • 打赏
  • 举报
回复
VBA中没试过,先Mark一下
Rita0120 2005-09-19
  • 打赏
  • 举报
回复
这些都是在VB中使用的亚,哪在VBA中的具体操作又是怎么样的亚?
道素 2005-09-19
  • 打赏
  • 举报
回复
如果控件很多建议使用控件数组,然后通过load方法加载
Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
If KeyAscii = 13 Then
Load Text1(Index + 1)
With Text1(Index + 1)
.Visible = True
.Top = Text1(Index).Top + Text1(Index).Height + 10
.Left = Text1(Index).Left
End With
End If
End Sub
weiweiplay 2005-09-19
  • 打赏
  • 举报
回复
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then NewTextBox "text1234"
End Sub

Public Sub NewTextBox(ByVal CtrlName As String)
Dim btnObj As Control
Set btnObj = Me.Controls.Add("VB.TextBox", CtrlName)
With btnObj
.Text = Text1.Text
.Top = Text1.Top + Text1.Height + 200
.Left = Text1.Left
.Height = Text1.Height
.Width = Text1.Width
.Visible = True
End With
End Sub

这样可以,呵呵
weiweiplay 2005-09-19
  • 打赏
  • 举报
回复
Public Sub NewTextBox(ByVal CtrlName As String)
Dim btnObj As Control
Set btnObj = Me.Controls.Add("VB.TextBox", "TextBoxName")
With btnObj
.Text = Text1.Text
.Top = Text1.Top + 200
.Left = Text1.Left
.Visible = True ‘改成TRUE
End With
End Sub

weiweiplay 2005-09-19
  • 打赏
  • 举报
回复
在TextBox得Keypresss事件种加入

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then NewTextBox CtrlName
End Sub

Public Sub NewTextBox(ByVal CtrlName As String)
Dim btnObj As Control
Set btnObj = Me.Controls.Add("VB.TextBox", "TextBoxName")
With btnObj
.Text = Text1.Text
.Top = 100
.Left = 100
.Visible = False
End With
End Sub

1,451

社区成员

发帖
与我相关
我的任务
社区描述
VB 控件
社区管理员
  • 控件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧