如何在VBA中使用循环功能填充许多texbox [英] How to fill many texbox by using loop function in VBA

查看:171
本文介绍了如何在VBA中使用循环功能填充许多texbox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VBA中创建了一个带有许多文本框的用户界面.我读了一张excel表,并将此表的所有值放在用户界面的所有文本框中.因此,用户可以修改值,然后将其保存在excel工作表中.

I made a user interface in VBA with many textbox. I read an excel sheet and I put all the value of this one in all the textbox of my user inteface. So the user can modify the values and then save it in the excel sheet.

因为我们无法将文本框命名为数组(textBox(1),textbox(2)....),所以很难使用循环函数来填充文本框.

Because we can't name the textbox like array (textBox(1), textbox(2)....) this is hard to fill the textbox by using a loop function.

我尝试使用tag或tabindex属性,但是我没有找到继续的好方法....有人知道解决此问题的简便方法吗!

I tried to use tag or tabindex property but I don't find the good way to proceed .... Is someone know an easy way to solve this !!!

谢谢

推荐答案

迭代表单的控件集合.

例如,假设您的用户表单名为myForm,然后

An example, say your user form is called myForm, then

myForm.Controls(i)

为您提供myForm中任何控件的句柄.现在,您可以使用控件属性来标识要查看的控件(标签,文本框,按钮等).建议您使用 Tag ,例如hmmmm ...."TEXTBOX",以简化id的过程.

gets you a handle for any control in myForm. Now you can use control properties to identify which one you're looking at (label, textbox, button, etc). I'd suggest you use a Tag such as, hmmmm.... "TEXTBOX", to ease the process of id.

if myForm.Controls(i).Tag="TEXTBOX" then 'it's my textbox ! hurraay!!!

这篇关于如何在VBA中使用循环功能填充许多texbox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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