Compartir a través de


GETOBJECT( ) Function

Activates an Automation object and creates a reference to the object.

GETOBJECT(cFileName | Moniker [, cClassName])

Returns

Object reference

Parameters

  • cFileName
    Specifies the full path and name of the file to activate. The application does not need to be specified, because the OLE dynamic link libraries determine the application to start based on the file name you provide.

    For example, the following code launches Microsoft Excel, opens a file named BUDGET.XLS, and creates a reference through an object variable named MBUDVAR:

    MBUDVAR = GETOBJECT('C:\EXCEL\WORK\BUDGET.XLS')
    
  • Moniker
    The identifier of a COM object that implements the IMoniker interface. A moniker can be any of the following types: file, item, generic composite, anti-, pointer, and URL. For details about COM monikers, search for "IMoniker" on the Microsoft Developer Network.

  • cClassName
    Specifies the class name of the object to retrieve. Some applications can store more than one object type in the same file, making it possible for you to use the class name to specify the object to activate. For example, if a word processing application stores its documents, macro definitions, and ToolBar objects in the same file, you can create a reference to the document file with the following command:

    MDOCFILE = GETOBJECT('C:\WRDPROC\MYDOC.DOC','WrdProc.Document')
    

    With some server applications, each time you issue GETOBJECT( ), an additional instance of the application is started, using additional memory. If the application is already running, you can prevent additional instances of the application from starting by omitting FileName and including ClassName, as in this example:

    oleApp = GETOBJECT(, "Excel.Application")
    

Remarks

Use GETOBJECT( ) to activate an Automation object from a file and to assign a reference to the object through a memory variable or array element.

If you specify an invalid file or class name, an OLE error is displayed, and the GETOBJECT( ) function returns an empty string.

Example

For example, on a network that has implemented Active Directory Services, you can query the network for information on a particular user.

   *  Replace "DomainName" with the domain name, and "UserLoginID"
   *  with the login ID of the user you are looking up.
   oUser = GetObject("WinNT://DomainName/UserLoginID,user")
   ? oUser.FullName

See Also

COMCLASSINFO( ) | CREATEOBJECT( ) | DEFINE CLASS | SET OLEOBJECT | GETINTERFACE( )