excel - 如何使用 VBA-Excell 检查特定名称的工作表上每个组合框的名称?
问题描述
我在工作表上有几个组合框,其对象名称包含单词 Product。我想选择每个组合框以更新列表项。
我已经设法识别组合框,但我似乎无法具体识别名称。
dim CBO as oleboject
set ws = sheets(1)
with sheets(1)
for each cbo in ws.oleobjects
if typename(cbo.object) = "ComboBox" then
THE CHECK HERE FAILS
end if
next cbo
end with
我无法获得识别对象名称的代码。
解决方案
所以我认为您需要事先检查以确保 typename 属性存在:
Sub ComboLoop()
Dim Ws As Worksheet
Dim OleObj As OLEObject
For Each Ws In ThisWorkbook.Worksheets
For Each OleObj In Ws.OLEObjects
If OleObj.OLEType = xlOLEControl Then
If TypeName(OleObj.Object) = "ComboBox" Then
With OleObj.Object
'SOME ACTIONS
End With
End If
End If
Next OleObj
Next Ws
End Sub
我过去使用过这段代码,它对我有用,所以希望它有所帮助。
推荐阅读
- typescript - 正确使用 PartiQL 和 AWS 开发工具包?
- devops - Bamboo - 如何在同一构建作业中合并代码后构建最新版本
- amazon-web-services - 克隆环境时如何更改平台分支?
- python - 禁用 Python 跨行自动连接字符串
- sql - 带有字符串连接的 SQL 很慢
- reactjs - MUI DataGrid 显示 Airtable 数据
- mysql - PowerShell MySQL 插入外来字符失败
- python - RGBA 参数无效:数组
- sql - postgreSQL 可以检索的最大记录数是多少?
- reactjs - TypeError: theme.~~ 不是带有样式组件的函数