Microsoft KB Archive/128994

{|
 * width="100%"|

INFO: Behavior of GETOBJECT with Excel and Word for Windows

 * }

-

The information in this article applies to:


 * Microsoft Visual FoxPro for Windows, versions 3.0, 6.0

-

SUMMARY
This article describes how the behavior of the GETOBJECT function is dependent on the OLE Server that processes the request. It focuses on the differences between Excel and WordBasic as OLE automation servers.

MORE INFORMATION
OLE and OLE automation are two primary means of sharing information. As an OLE client, Visual FoxPro can control external data from other applications. As OLE automation servers, Microsoft Word (through WordBasic) and Excel support incoming OLE requests. Because OLE is still evolving, OLE automation servers do not support all requests the same way. For example, Word for Windows, version 6.0c and Excel version 5.0 do not identically support the request made by the GETOBJECT function.

The GETOBJECT function retrieves an OLE Automation object and creates a reference to that object. It has two arguments, a file name and a class name.

For example, to retrieve and create a reference to an Excel spreadsheet, you can use this syntax:



 cBudget=GETOBJECT('C:\Excel\Mysheet.XLS ','Excel.Application') Passing an empty string as the first argument to the GETOBJECT function results in different behaviors with Excel version 5.0 or Word as OLE automation servers:

 If the first argument is an empty string, GETOBJECT will create a new instance of the specified class. Its functionality is identical to CREATEOBJECT. For example:

  GETOBJECT("","Excel.Application") always starts a new instance of Excel version 5.0. This technique returns an error message in Excel version 7.0. For more information, please see the following article in the Microsoft Knowledge Base: "Q147573 PRB:Excel 7.0 Not Registering in the Running Object Table" GETOBJECT("","Word.Basic") starts a new instance of Word if Word for Windows is not running. If an instance of Word already exists, CREATEOBJECT creates an object reference to the current instance.  If the first argument is not passed, GETOBJECT(,"Excel.Application") attempts to get an existing instance in Excel. If there is an instance of Excel, a reference to the object is made. If no instance of Excel is running, the error "OLE code 0x800401e3: Operation Unavailable" is returned.

NOTE: The syntax GETOBJECT(,"Word.Basic") always fails. The error "OLE error code 0x800401e3: Operation Unavailable" is returned when no argument is passed to a WordBasic class.