-1

Run-time error '429': ActiveX component can't create object当我尝试运行以下代码时出现错误。

Option Explicit

Private Sub EarlyVsLateBinding()

    ' References to both the Microsoft Scripting Runtime and Microsoft XML, v6.0 
    ' are active so that early binding is possible

    Dim EarlyDictionary As Scripting.Dictionary
    
    Dim LateDictionary As Object
    Set LateDictionary = CreateObject("Scripting.Dictionary")
    
    Dim EarlyHTTP As New MSXML2.XMLHTTP60
    
    Dim LateHTTP As Object
    Set LateHTTP = CreateObject("MSXML2.XMLHTTP60") ' Error is thrown here

End Sub

我已经包含了这个例子Scripting.Dictionary来说服自己这个CreateObject函数没有引起任何问题,并表明一个早期和晚期绑定适用于另一个类。

可悲的是,我遇到的这个类的每个示例都使用早期绑定方法,但我需要此代码的后期绑定方法。此外,将行替换为Set LateHTTP = CreateObject("MSXML2.XMLHTTP60")产生Set LateHTTP = GetObject(Class:="MSXML2.XMLHTTP60")相同的错误。

什么可能导致此错误?

4

1 回答 1

0

正如@Raymon Wu 在问题评论中指出的那样,换行

Set LateHTTP = CreateObject("MSXML2.XMLHTTP60")

Set LateHTTP = CreateObject("MSXML2.XMLHTTP")

部分工作。


编辑 1

或者,正如@KL-1 在评论中指出的那样,将行更改为

Set LateHTTP = CreateObject("MSXML.XMLHTTP.6.0")

也解决了这个问题。


This change does make the code in my question run without error. However, this caused another error later in a different piece of code

LateHTTP.setRequestHeader bstrHeader:="Content-Type", bstrValue:="application/json"

which was the Run-time error '448': Named argument not found error. This was fixed by removing the named arguments and changing the line to

LateHTTP.setRequestHeader "Content-Type", "application/json"


Edit 1

Note that both solutions caused this Run-time error '448'.

As others have pointed out in the comments, when binding classes, the names are not necessarily the same when using early vs late.

The names for late binding can be found in the computer's registry editor under Computer\HKEY_CLASSES_ROOT.


I am aware that this goes beyond the scope of the question, but I consider it relevant information.

于 2022-02-10T08:16:07.747 回答