可以使用变量在VBA代码中指定标签名称吗? [英] Can a variable be used to designate a label name in VBA code?

查看:158
本文介绍了可以使用变量在VBA代码中指定标签名称吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我如何使用变量来规定以下VBA代码中的标签名称吗?

'[Forms]![F3-subject index]![sn5] .Caption =" string"

'[Forms]![F3-subject index]![sn5].Caption = "string"

我想使用一个变量instread的" ; SN5"我还没有找到任何方法将变量替换为上面的表达式。

I want to use a variable instread of the "sn5"  I have not found any way to substitute a variable into the expression above.

我有100多个标签值,如果我可以使用数组,可以很容易地插入到我的表单中我的VBA代码中带有循环例程的变量。我认为这在VBA中是不可能的,但只在DAO中。不幸的是,我对DAO一无所知。可以在VBA中完成吗?如果没有,还有其他办法吗?下面是我想要做的一个例子,但无论我多么混乱语法,它都会生成错误消息。

I have 100 plus label values which could be easily inserted into my form if I could just use an array variable with a Loop routine in my VBA code.  I am thinking it is not possible in VBA, but only in DAO.  Unfortunately, I know nothing of DAO.  Can it be done in VBA?  IF not, is there any other way to do it?  Below is an example of what I want to do, but it generates error messages no matter how much I mess with the syntax.

对于CT = 1到100

For CT = 1 to 100

[Forms]![F3-subject index]![" sn"& CT] .Caption = valuearray(CT)

[Forms]![F3-subject index]!["sn"&CT].Caption=valuearray(CT)

next CT

推荐答案

好的我猜的不多但是在这里去吧。

Ok I don't guess much but here it goes.

Dim lbl as label

Dim lbl as label

lbl。 Caption =" string"

lbl.Caption = "string"

[Forms]![F3-subject index]![sn5] = label

[Forms]![F3-subject index]![sn5] = label

ADT


这篇关于可以使用变量在VBA代码中指定标签名称吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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