相关疑难解决方法(0)

如何防止在 VBA 中触发 ActiveX 事件?

我正在寻找一种更好的方法来禁止在 Excel 工作簿中触发 ActiveX 事件(尽管这适用于所有带有 ActiveX 对象的 Office 应用程序)。

希望类似于Application.EnableEvents = false,尽管这不适用于 ActiveX。

在下面的示例中,使用全局布尔值是微不足道的,但是我的 ActiveX 对象有很多事件处理程序,并且对于我可以普遍应用的临时禁用 ActiveX 事件的东西来说会非常容易。我真的不想为这些方法中的每一个添加 if/exit 子语句。

为了演示这个问题,在工作表中创建一个 ActiveX 组合框并将以下内容添加到该工作表模块

Public initializingContent As Boolean 
Private Sub intializeAllActiveXContent()

    'this doesn't apply to activeX events :'(
    Application.EnableEvents = False

    'this could work but is not really elegant
    'change this to false to show my problem in 
    'the intermediate window (called not once but twice)
    initializingContent = True

    ComboBoxTest.Clear

    ComboBoxTest.AddItem ("item1")
    ComboBoxTest.AddItem ("item2")
    ComboBoxTest.AddItem ("item3")

    'select the top …
Run Code Online (Sandbox Code Playgroud)

excel vba activex

4
推荐指数
2
解决办法
6848
查看次数

标签 统计

activex ×1

excel ×1

vba ×1