首页 > 解决方案 > 无法在 VBA 中创建 Scripting.Dictionary 或 MSXML.DOMDocument60,因为 Windows 更新 KB4586781

问题描述

从标准库(如 Microsoft Scripting Runtime 或 Microsoft Xml, v6.0)创建 COM 对象时,某些 VBA 代码不再适用于我。我在实例化行出现错误,错误是代码 80004021(-2147467231),错误描述是Automation error The operation attempted is not supported. 但是我可以创建具有对这些库的互操作引用的 C# 代码非常好。两天前我有一个Windows 10 更新 KB4586781

Excel VBA 和 Word VBA 中的代码均失败。还有其他人有类似问题吗?

Sub TestCreate_Scripting_Dictionary()
    
    '* THIS CODE FAILS !!!!
    
    Dim lateBound As Object
    Set lateBound = VBA.CreateObject("Scripting.Dictionary") '<=== FAILS 80004021
    ' ... Automation error The operation attempted is not supported.
    
    '* Tools->References->Microsoft Scripting Runtime
    Dim dict As Scripting.Dictionary
    Set dict = New Scripting.Dictionary  '<=== FAILS 80004021
    ' ... Automation error The operation attempted is not supported.


End Sub


Sub TestCreate_MSXML2_DOMDocument60()
    '* THIS CODE FAILS !!!!

    '* Tools->References->Microsoft Xml, v6.0
    Dim xml As MSXML2.DOMDocument60
    Set xml = New MSXML2.DOMDocument60  '<=== FAILS 80004021
    ' ... Automation error The operation attempted is not supported.
    

End Sub

更新:我打算重新安装,但它没有任何干预就消失了。奇怪的。

标签: excelvbams-wordwindows-update

解决方案


推荐阅读