vba - 通过字符串提供控件名称
问题描述
“Me.strLblName.FontBold = True”不起作用。我已经尝试过 Me.& strLblName &.FontBold = True 以及许多其他人。这是语法问题还是我需要另一种方法?
**Private Sub Form_Load()
Dim ctl As Control, intUsage As Integer, strCtlName As String, strLblName As String
For Each ctl In Me.Form.Controls
Select Case ctl.ControlType
Case acCommandButton
intUsage = DLookup("process_usage", "tbl_db_stats", "cbtn_name = '" & ctl.Name & "'")
Debug.Print ctl.ControlType, ctl.Name, intUsage
strLblName = "lbl_" & Right(ctl.Name, Len(ctl.Name) - 5)
If intUsage < 10 Then
Stop
'CHANGE LABEL TEXT TO BOLD
Me.strLblName.FontBold = True
End If
End Select
Next ctl
End Sub**
解决方案
Controls(strLblName).FontBold = True
推荐阅读
- c++ - File.exe 已因 Fseek 触发断点
- google-apps-script - 获取 Google 表格值时保持“表格状态”
- javascript - SOCKET.IO 监听 HTTPS
- python - 将 2 个列表与嵌套的 for 循环进行比较
- javascript - Angular:垃圾收集组件
- php - 使用服务器进行身份验证时出错,但如果我得到答案则使用 Postman
- clang - doxygen 1.8.17 clang 崩溃
- pandas - Groupby 和 Sum 在单列上并找到最大值
- php - 未知错误:无法使用 Symfony Panther 在 Laravel 中为用户数据目录创建临时目录
- javascript - 如何在 d3js 中的每个值线的每个点上附加一个圆圈?