vba excel。如何在运行时创建文本框,并命名它们。 [英] vba excel. how to create textboxes during runtime, and name them.

查看:379
本文介绍了vba excel。如何在运行时创建文本框,并命名它们。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨。我试图在运行时创建文本框,然后命名它们。

Hi. i am trying to create textboxes during runtime, and then naming them.

我已经设法在运行时创建一个文本框,但是,我似乎无法命名。

I have managed to create a single textbox during runtime, however, i cant seem to name it.

我想要做的是在运行时创建一些文本框,并以不同的方式命名它们,这样我就可以将值存储到它们中。

what i am trying to do is to create a number of textboxes during runtime, and name them each differently, so i can store values into them.

For i = 0 To 5

 Set txtB1 = Controls.Add("Forms.TextBox.1")
txtB1.Name = "chkDemo(i)" ' after assigning name to txtB1, i couldnt seem to include values for the new name
chkDemo(i) = "hihi" ' error appears on this line

Next

我希望能够在运行时创建动态文本框,每个文本框名称的值随参考值的增加而增加到for循环。

I would like to be able to create dynamic textboxes during runtime with each textbox name increasing in value with reference to the for loop.

TextBox1,TextBox2,TextBox3等

TextBox1,TextBox2,TextBox3 etc

推荐答案

在名为UF1的UserForm上,以下工作原理:

On a UserForm named UF1 the following works:

Private Sub UserForm_Initialize()
    UF1.Controls.Add "Forms.TextBox.1", "Name1", True
    UF1!Name1.Text = "Hi"
End Sub


这篇关于vba excel。如何在运行时创建文本框,并命名它们。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆