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

查看:16
本文介绍了如何在 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天全站免登陆