Microsoft Office 2000/Visual Basic Programmer's Guide |
When you install the Office 2000 applications, one of the object libraries installed on your system is the Microsoft Scripting Runtime object library. This object library contains objects that are useful from either VBA or script, so it's provided as a separate library.
The objects in the Scripting Runtime library provide easy access to the file system, and make reading and writing to a text file much simpler than it is in previous versions.
By default, no reference is set to this library, so you must set a reference before you can use it. If Microsoft Scripting Runtime does not appear in the References dialog box (Tools menu), you should be able to find it in the C:\Windows\System subfolder as Scrrun.dll.
The top-level objects in the Scripting Runtime object library are the Dictionary object and the FileSystemObject object. To use the Dictionary object, you create an object variable of type Dictionary, then set it to a new instance of a Dictionary object:
Dim dctDict As Dictionary
Set dctDict = New Dictionary
To use the other objects in the Scripting Runtime library in code, you must first create a variable of type FileSystemObject, and then use the New keyword to create a new instance of the FileSystemObject, as shown in the following code fragment:
Dim fsoSysObj As FileSystemObject
Set fsoSysObj = New FileSystemObject
You can then use the variable that refers to the FileSystemObject to work with the Drive, Folder, File, and TextStream objects.
The following table describes the objects contained in the Scripting Runtime library.
Object | Collection | Description |
Dictionary | Top-level object. Similar to the VBA Collection object. | |
Drive | Drives | Refers to a drive or collection of drives on the system. |
File | Files | Refers to a file or collection of files in the file system. |
FileSystemObject | Top-level object. Use this object to access drives, folders, and files in the file system. | |
Folder | Folders | Refers to a folder or collection of folders in the file system. |
TextStream | Refers to a stream of text that is read from, written to, or appended to a text file. |