excel - vba 将控制称为变量语法
问题描述
我正在使用 VBA 创建控件,并且无法通过将它们称为控件来设置字体。我给它们命名,如果我按名称引用它们,我可以修改字体。
我需要知道正确的语法才能完成这项工作。我想我已经尝试了所有组合,但没有一个成功。Me.(control variable name).Font
For CountRecords = 0 To rs.RecordCount - 1
tempLeft = 6
For countfields = 0 To rs.Fields.Count - 1
tempname = rs.Fields.Item(countfields).Name & CountRecords
frmtst.Controls.Add "forms.textbox.1", tempname
Set ctl = Me.frmtst(tempname)
Me.test.Font = 14 'set the font on a test textbox
Me.Controls(tempname).Value.Font = 14 '****Trouble line ********
ctl.Width = ((columnwidth(countfields) ^ 0.8) * 10) + 25
ctl.Height = 24
ctl.Left = tempLeft 'templeft + columnwidth(CountFields) + 18
tempLeft = tempLeft + ctl.Width + 3
ctl.Top = 20 * CountRecords + 3
ctl = rs.Fields.Item(countfields).Value
If rs.Fields.Item(countfields).Type = 6 Then
ctl = Format(ctl, "$#,##0.00")
end if
Next countfields
rs.MoveNext
Next CountRecords
解决方案
在表单过程中使用 Me 可以替代frmtst
上面的表单名称。Me.frmtst(tempname)
双重参考也是如此。tempname
您可以使用参考控件Me.tempname
。设置字体Me.tempname.Font.Name = "Lucida Console"
和设置字体大小Me.tempname.Font.Size = 10
推荐阅读
- css - 如何使用 Tailwind CSS 在表格中居中图像?
- python - sklearn 管道索引不匹配
- c - 如何将此数字表示形式转换为浮点数?
- python-3.x - 跨平台动态终端打印
- java - 焦点转移后执行 Runnable 的正确方法
- linux - 如何从 horsicq github 在 ubuntu 20.04 上轻松构建检测它?
- c++ - 为什么默认复制构造函数不适用于此类
- c++ - 用 char 符号复制 char*
- python - 如何删除字符串中某个单词的实例和可能的多个实例并返回一个字符串(CODEWARS dubstep)
- javascript - 我如何制作一个 js 代码来重定向到具有特定输入的特定 html 页面?