PRB: OLE Automation Err: Method Not Applicable for This Object

Last reviewed: September 29, 1997
Article ID: Q115859
The information in this article applies to:

- Standard and Professional Editions of Microsoft Visual Basic for

  Windows, version 3.0

SYMPTOMS

Certain valid OLE Automation methods cause the following error in Visual Basic:

   Method not Applicable for This Object.

CAUSE

This occurs if the method is a reserved word in Visual Basic. For example, Close is a reserved word in Visual Basic. If you try to use Close in an OLE Automation command, the Visual Basic parser complains and gives you the error message.

RESOLUTION

To use OLE Automation methods that are reserved words in Visual Basic, use the [] notation. For example, wrap the word Close in square brackets. This stops Visual Basic from trying to interpret Close as a Visual Basic statement.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Start a new project Visual Basic. Form1 is created by default.

  2. Add a command button (Command1) to Form1.

  3. Add the following code to the Command1 Click event procedure:

          Sub Command1_Click ()
             Dim sheet As Object
             Set sheet = CreateObject("Excel.Sheet.5")
             ' The following line causes the "Method not Applicable for
             ' This Object" error:
             sheet.Parent.Close
             Set sheet = Nothing
             MsgBox "Excel Object created and destroyed successfully!"
          End Sub
    
    

  4. Run the application. You will get a "Method not Applicable for This Object" error on the line of code that reads:

          sheet.Parent.Close
    

  5. Place square brackets around the word Close in the highlighted line. The line should now read:

          sheet.Parent.[Close]
    

  6. Run the program. It should run without error.
Keywords          : IAPOLE vbwin GnrlVb kberrmsg kbprg
Technology        : kbole kbvba
Version           : WINDOWS:3.0
Platform          : WINDOWS
Issue type        : kbprb


================================================================================


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: September 29, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.