【发布时间】:2019-09-29 02:42:01
【问题描述】:
VBA 我需要动态生成选项按钮的名称。选项按钮是用户表单上的表单控件选项按钮。我在模块中有以下代码,而不是在用户表单的后面代码中
Sub Test_Form()
Dim MyOptionButton As String
Dim OptionButton As String
Dim i As Integer
i = 1
MyOptionButton = OptionButton & i
'I'm hoping the compiler will understand this as "OptionButton1"
If Range("C2").Value = 5 Then
MyOptionButton.Value = True
'Error message here: "invalid qualifier"
End If
frmTest_Form.Show
End Sub
看来编译器需要将控件名称预定义为“OptionButton1”,并且不会将 MyOptionButton 读取为“OptionButton1”。
提前感谢您的帮助。
【问题讨论】:
-
您要解决的选项按钮在哪里?在工作表上?它是什么类型的选项按钮 - 表单或 ActiveX?
-
您很可能必须找到替代方法,例如使用
Tag属性,并具有通过控件搜索Tag而不是Name的函数, -
MyOptionButton = "OptionButton" & i然后您需要使用该名称索引到ActiveSheet.Shapes()之类的内容 -
选项按钮是用户表单上的表单控件按钮。
-
你的选项按钮是字符串,不能作为控件,请试试controls(myopt button).value
标签: excel vba radio-button