Question about CreateObject () in VB6 / VBA

I can do it:

Dim fso As New FileSystemObject 

or I can do this:

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

How to find out which line to use for CreateObject? For example, how can I use "Scripting". part of "Scripting.FileSystemObject"? Where are you going to see this?

+10
vba vb6 late-binding createobject
Dec 05 '08 at 21:19
source share
3 answers

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

 HKEY_CLASSES_ROOT\Scripting.FileSystemObject 

ProgIDs are humanoid identifiers for COM objects. They indicate the actual CLSID, which in this case:

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

This is the place where you can find the actual COM-DLL, which includes the component implementation.

In the first code example that you specified, you are performing early binding, and in the second, the last binding.

+20
Dec 05 '08 at 21:22
source share

Using the VB6 IDE, select Project, Links, then select the Microsoft Scripting Runtime link.

If you did not know what the link was called, you can use the browse button of the browse dialog box to select the / system 32 / scrrun.dll file.

With the link selected, close the Links dialog box, then open Object Browser (View menu). Change the drop-down list to the most likely candidate, being "Scripting". This will open the library classes, one of which is "FileSystemObject". Therefore, you will find that the line required for CreateObject is "Scripting.FileSystemObject".

If you don't know the link name or file name, but you know the class name, then you can search the registry for "FileSystemObject" and it should soon be found that you need "Scripting.FileSystemObject" for the full name.

+2
Dec 09 '08 at 10:55
source share

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

The site is filled with documentation, including information on how to call CreateObject.

+1
Dec 05 '08 at 21:35
source share



All Articles