Retrieves an existing object with the specified ProgID, or creates a new one from a file.
|
---|
object.GetObject(strPathname [,strProgID], [strPrefix]) |
Arguments
- object
WScript object.
- strPathname
The fully qualified path name of the file that contains the object persisted to disk.
- strProgID
Optional. The object's program identifier (ProgID).
- strPrefix
Optional. Used when you want to sync the object's events. If you supply the strPrefix argument, WSH connects the object's outgoing interface to the script file after creating the object.
Remarks
Example
The following VBScript code starts the application associated with the specified file (strPathname):
| Copy Code |
---|
Dim MyObject As Object
Set MyObject = GetObject("C:\CAD\SCHEMA.CAD")
MyApp = MyObject.Application |
Some applications allow you to activate part of a file. To do this, add an exclamation mark (!) to the end of the file name, and follow it with a string that identifies the part of the file you want to activate. For example, in a drawing application, a drawing stored in a file might have multiple layers. The following code activates a layer within a drawing file called SCHEMA.CAD
:
| Copy Code |
---|
Set LayerObject = GetObject("C:\CAD\SCHEMA.CAD!Layer3") |
If you do not specify the object's class (strProgID), COM determines the application to start from the file name. Some files can support more than one class of object. For example, a drawing might support three different types of objects: an application object, a drawing object, and a toolbar object. All may be part of the same file.
In the following VBScript code, the drawing application FIGMENT
starts and opens the object DRAWING
from within the file SAMPLE.DRW
.
| Copy Code |
---|
Dim MyObject As Object
Set MyObject = GetObject("C:\DRAWINGS\SAMPLE.DRW", "FIGMENT.DRAWING") |
See Also