13

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?

3 Answers 3

25

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.

3

Using the VB6 IDE, choose Project, References, then to pick the reference 'Microsoft Scripting Runtime'.

If you didn't know what the reference is called, you could use the References dialog's Browse button to pick the file /system 32/scrrun.dll.

With the reference chosen, close the References dialog then open the Object Browser (View menu). Change the dropdown to the most likely candidate, being 'Scripting'. This will reveal the library's classes, one of which is 'FileSystemObject'. Hence, you will have discovered the the string required for CreateObject is 'Scripting.FileSystemObject'.

If you didn't know the Reference name or the file name but you did know the class name then you could search the registry for "FileSystemObject" and it should soon be revealed that the fully-qualified name you require is 'Scripting.FileSystemObject'.

1

I would start by searching for FileSystemObject in the MSDN library at http://msdn.microsoft.com/library

The site is chock full of documentation, including the details of how to call CreateObject.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.