excel - 当工作表处于非活动状态或窗口最小化时,无法设置 OLEObjects 属性
问题描述
我正在尝试通过在工作表中设置一些 OLE 对象的属性来初始化 Excel 工作表,并将下面的代码放在标准模块中。
With ThisWorkbook.Worksheets("UserView")
.btnShowAllItems.Enabled = False
.btnShowAllItems.Visible = False
.btnAvailableOnly.Enabled = True
.btnAvailableOnly.Visible = True
.AutoFilter.ShowAllData
End With
上面的代码按预期工作,除非在 Excel 窗口最小化或用户在不同的工作表中调用 sub 时,导致以下错误。
Run-time error '1004':
Unable to set the Enabled property of the OLEObject class
我究竟做错了什么?当 Excel 窗口最小化或用户在不同的工作表中时,如何设置属性?
解决方案
.Object
打电话时尝试添加Enabled
- 为我解决了这个问题
With ThisWorkbook.Worksheets("UserView")
.btnShowAllItems.Object.Enabled = False
.btnShowAllItems.Visible = False
.btnAvailableOnly.Object.Enabled = True
.btnAvailableOnly.Visible = True
.AutoFilter.ShowAllData
End With
推荐阅读
- android - 仅从 API Kotlin 获取 null
- python - 根据 pandas 中另一个数据帧的掩码值在数据帧中生成 NaN
- python - 将在不同工作机器上创建的数据帧连接成一个数据帧
- sql - 创建 SQL 查询以查找整个 Redshift 数据库中包含特定文本字符串(数据)的所有表
- ckeditor - 在 IIS 和 localhost 中的子目录上托管时出错
- python - FLASK-WTF 更新唯一列 PYTHON/FLASK/SQLITE
- angular - 我如何找出哪些包会受到另一个包的更新的影响?
- android - React Native Android 前台推送通知与 iOS 不一致
- java - 使用 Reader 和 Writer 的压缩算法
- elasticsearch - 桶术语聚合 Elasticsearch