XL5: OLE Automation Error Using Quit Method with GetObject

ID: Q114225

The information in this article applies to:

SYMPTOMS

When you use the GetObject function with a filename in a Microsoft Visual Basic version 3.0 procedure to open a Microsoft Excel workbook, and then use the Quit method to quit Microsoft Excel, the following error message appears:

   OLE Automation error. Worksheet does not have Quit method.

CAUSE

When you use the GetObject function with a filename to open a file, the OLE Automation object that is created is a Worksheet object, not an Application object. This error occurs when you use the Quit method with a Worksheet object, because the Quit method does not apply to a Worksheet object.

WORKAROUND

Microsoft provides examples of Visual Basic for Applications procedures for illustration only, without warranty either expressed or implied, including, but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft support professionals can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400.

To use the Quit method to quit Microsoft Excel after creating an OLE Automation object in an application that uses Visual Basic, use one of the following methods:

Method 1

Use the Parent property to return the Application object and use the Quit method as in the following Visual Basic procedure:

      ' Dimension variable x as Object type
      Dim x As Object
      ' Set x equal to Microsoft Excel Worksheet object
      Set x = GetObject("C:\EXCEL\BOOK1.XLS")
      ' Quit Microsoft Excel
      x.Application.Quit

Method 2

Use the class argument of the GetObject function to return the Application object as the OLE Automation object. Then open the desired workbook file as in the following Visual Basic procedure:

      ' Dimension variable x as object type
      Dim x As Object
      ' Set x equal to Microsoft Excel Application object
      Set x = GetObject("", "Excel.Application.5")
      ' Open workbook BOOK1.XLS
      x.Workbooks.Open "C:\EXCEL\BOOK1.XLS"
      ' Quit Microsoft Excel
      x.Quit

STATUS

Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

For additional information, please see the following articles in the Microsoft Knowledge Base:

   ARTICLE-ID: Q111247
   TITLE     : XL OLE Automation: Workbook Hidden Using GetObject Function

   ARTICLE-ID: Q134835
   TITLE     : Automation Error Using Excel Object in Visual Basic
               Procedure

REFERENCES

For more information about the Quit Method, click the Search in the Visual Basic Reference and type:

   Quit Method

Additional query words: 5.00 3.00
Keywords          : kbinterop kbprg 
Version           : 5.00
Platform          : WINDOWS

Last Reviewed: May 17, 1999