-1

I am getting a Run-time error '429': ActiveX component can't create object error when I try to run the following code.

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

I have included the example of Scripting.Dictionary to convince myself that the CreateObject function wasn't causing any issues, and to show that an early and late binding work for another class.

Sadly, every example that I come across of this class uses the early binding method but I need the late binding method for this code. Also, replacing the line Set LateHTTP = CreateObject("MSXML2.XMLHTTP60") with Set LateHTTP = GetObject(Class:="MSXML2.XMLHTTP60") yielded the same error.

What could be causing this error?

TehDrunkSailor
  • 633
  • 4
  • 11

1 Answers1

0

As @Raymon Wu pointed out in the comments of the question, changing the line

Set LateHTTP = CreateObject("MSXML2.XMLHTTP60")

to

Set LateHTTP = CreateObject("MSXML2.XMLHTTP")

worked partially.


Edit 1

Alternatively, as @KL-1 has pointed out in the comments, changing the line to

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

fixed the issue as well.


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.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
TehDrunkSailor
  • 633
  • 4
  • 11
  • The decimal points are wrong as I said before. – KL-1 Feb 10 '22 at 16:04
  • 1
    Depending on early or late binding a) Early binding (library: "Microsoft XML, v6.0") is referenced without points in the declared versioning suffix (`MSXML2.XMLHTTP60`). b) Late binding in its current version includes points; if you'd **omit** the entire versioning suffix **`.6.0`** in `Set LateHTTP = CreateObject("MSXML2.XMLHTTP.6.0")`, you'll bind automatically to *version 3.0.*, which is the last stable version before the current version 6.0 @TehDrunkSailor – T.M. Feb 10 '22 at 17:32
  • @KL-1 Do you know why that would cause this 448 error though? I can't see why a change like that would force you to stop using named arguments in functions or subroutines. – TehDrunkSailor Feb 11 '22 at 05:27