[英]Define a control caption on a form in vba using a variable to define the control
请让我重新开始。
我有一个用户表单,SortForm,上面有 30 个单选按钮。 该表单的目的是允许用户选择其中一个按钮作为对电子表格进行排序的键。 它正在对课程进行排序,并且每个注册期都会发生变化。
我试图做的是更改单选按钮的标题以反映课程名称。 我已将电子表格中的信息存储到两个数组中,strSortName 和 intSortCol。 strSortName 包含课程名称。 每个单选按钮名称都以“btSort”开头,然后是 1 到 30 的数字。我想要做的是使用“btsort”和我的 do 循环中的索引的连接来更新按钮的标题以反映课程名称包含在 strSortName
我希望这是一个更好的问题
查理
迄今为止的代码,坚持更新字幕
Sub macSortData() ' ' macSortData 宏 ' ' 键盘快捷键:Ctrl+Shift+S '
Dim strVal1 As String, intVal2 As Integer, I As Integer Dim FormName As String ' 不确定是否需要 Dim ControlName As Controls ' 不确定这是否需要或正确 Dim intSortCol(34), strSortName(34) As String
工作表(“主要”)。激活
对于 I = 1 到 34
''strVal1 包含课程名称,strVal2 包含课程的列号
strVal1 = Cells(4, I + 2).Value
intVal2 = I + 2
'结束类列表的测试
If Len(strVal1) = 0 Then GoTo sortFinal
If strVal1 = "# taken" Then GoTo sortFinal
'在数组中存储名称和列号
strSortName(I) = strVal1 intSortCol(I) = intVal2
'非工作字幕更新代码Set ControlName = "btsort" & Trim(str(I)) ' 连接的控件名称
SortForm.ControlName.Caption = strSortName(I) '非工作分配尝试
接下来我
排序最终:
'显示表格SortForm.Show
结束子
有效的代码是
ControlName = "btsort" & Trim(str(I))
SortForm.Controls(ControlName).Caption = Trim(strSortName(I))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.