Question about CreateObject() in VB6 / VBA

Shane Miskin picture Shane Miskin · Dec 5, 2008 · Viewed 12.4k times · Source

I can do this:

Dim fso As New FileSystemObject

or I can do this:

Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")

How do I know what string to use for CreateObject? For example, how would I know to use the "Scripting." part of "Scripting.FileSystemObject"? Where do you go to look that up?

Answer

huseyint picture huseyint · Dec 5, 2008

It is the ProgID of the component which is registered in Windows registry under HKCR key:

HKEY_CLASSES_ROOT\Scripting.FileSystemObject

ProgID's are human readable identifiers for COM objects. They point to the actual CLSIDs, which in this case is:

HKEY_CLASSES_ROOT\CLSID\{0D43FE01-F093-11CF-8940-00A0C9054228}

This is the place where you can find the actual COM .dll that includes the implementation of the component.

In the first sample code you have provided you are doing an early-binding, and in the second one you are doing a late-binding.