Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBA CreateObject("MSXML2.DOMDocument60") throws an Error 429

I'm having trouble declaring new object using CreateObject()

Sub A()
    Dim x

    'This works
    Set x = CreateObject("Scripting.FileSystemObject")
    Set x = Nothing

    'This throws an error 429 "Active component cannot create object."
    Set x = CreateObject("MSXML2.DOMDocument60")
    Set x = Nothing

    'The only way I can create object is to add the reference using GUID
    Dim y As MSXML2.DOMDocument60
    Set y = New MSXML2.DOMDocument60
    Set y = Nothing
    'This works like a charm

End Sub

I don't understand why "scripting" works and "MSXML2" does not.

I'm using MS Access 2010 32 bit on Windows 7 64 bit.

like image 490
Combinatix Avatar asked May 05 '16 09:05

Combinatix


1 Answers

You don't always use the same name when using late binding. ActiveX objects require the OLE Programmatic Identifier to be used.

Change it to this:

Set x = CreateObject("MSXML2.DOMDocument.6.0")

From the MSDN article Building MSXML Applications:

When you are using a scripting language, you can identify the control via its ProgID, which is a form that is quite a bit easier to read by a human. An example of a ProgID is Msxml2.DOMDocument.6.0.


like image 84
SierraOscar Avatar answered Nov 10 '22 23:11

SierraOscar