Behavior of GETOBJECT() with Excel and Word for Windows

Last reviewed: April 30, 1996
Article ID: Q128994
The information in this article applies to:
  • Microsoft Visual FoxPro for Windows, version 3.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:
    

          ARTICLE-ID: Q147573
    
          TITLE     : 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.

REFERENCES

For a list of OLE automation verbs supported by Excel version 5.0, please see the Excel Object Browser.

For a list of WordBasic OLE automation verbs, please see the "Using Word Basic" guide.

For more information about Microsoft OLE automation servers, please see the Office Developer's Kit.


Additional reference words: 3.00 VFoxWin
KBCategory: kbinterop
KBSubcategory: FxinteropOle


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 30, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.