What are the differences between using the New keyword and calling CreateObject in Excel VBA?

As long as the variable is not typed as object

Dim xmlDocument as MSXML2.DOMDocument
Set xmlDocument = CreateObject("MSXML2.DOMDocument")

is the same as

Dim xmlDocument as MSXML2.DOMDocument
Set xmlDocument = New MSXML2.DOMDocument

both use early binding. Whereas

Dim xmlDocument as Object
Set xmlDocument = CreateObject("MSXML2.DOMDocument")

uses late binding. See MSDN here.

When you’re creating externally provided objects, there are no differences between the New operator, declaring a variable As New, and using the CreateObject function.

New requires that a type library is referenced. Whereas CreateObject uses the registry.

CreateObject can be used to create an object on a remote machine.

Leave a Comment