BUG: XL97 Errors Using OLE Automation

Last reviewed: July 31, 1997
Article ID: Q165273
The information in this article applies to:
  • Microsoft Visual C++, 32-bit Editions, versions 2.0, 2.1, 2.2, 4.0, 4.0a, 4.1, 4.2, 4.2b, 5.0

SYMPTOMS

OLE Automation code that successfully controlled previous versions of Microsoft Excel may fail with Microsoft Excel 97. If the code was generated by a scripting language, you may get an error message similar to the following:

   “Method does not exist”

CAUSE

This problem can be caused by an improperly implemented OLE Automation Controller. An OLE Automation Controller actually makes the calls to a server application's IDispatch interface to allow that server to be controlled by the client.

In this case, the problem relates to how the IDispatch::Invoke method is called. The Invoke method requires that you specify the context of the IDispatch call by passing one or more of the following flags via the wFlags parameter:

  • DISPATCH_METHOD
  • DISPATCH_PROPERTYGET
  • DISPATCH_PROPERTYPUT
  • DISPATCH_PROPERTYPUTREF

These flags indicate whether the function being called via IDispatch should be called as a property or a method.

Previous versions of Microsoft Excel implemented their collection accessor functions as methods. For example, consider the following line of Visual Basic For Applications, Excel edition code:

      Workbooks(1).Worksheets(1).Range("A1").Value = 10

Workbooks, Worksheets, and Range are implemented as methods in Microsoft Excel version 5.0 and 7.0. However, Microsoft Excel 97 implements these same calls as properties.

If OLE Automation Controllers break when they try to drive Microsoft Excel 97, it is usually because they are passing DISPATCH_METHOD as the wFlags parameter of IDispatch::Invoke. Because these functions are no longer implemented as methods in Microsoft Excel 97, the Invoke method will fail with DISP_E_MEMBERNOTFOUND. If you are using a scripting language on top of the controller, you will generally get an error message similar to the one mentioned above.

RESOLUTION

To resolve this problem, modify the OLE Automation Controller code so that calls to IDispatch::Invoke include DISPATCH_PROPERTYGET as part of the wFlags parameter. Though you can pass DISPATCH_PROPERTYGET by itself where these property calls are being made, the best solution is to logically OR this flag with DISPATCH_METHOD (DISPATCH_PROPERTYGET | DISPATCH_METHOD). By doing this, you ensure that the function call will succeed regardless of whether it has been implemented as a property or a method.

It should be emphasized that this problem is not a problem in Microsoft Excel. The problem lies in the implementation of the OLE Automation Controller. The only solution to this problem is to fix the OLE Automation Controller code.

Customers who did not write the OLE Automation Controller (such as those who may be using a scripting language) should contact their vendor for support.

To confirm that this is a problem in the controller code, Visual Basic should be used to automate Microsoft Excel in the fashion attempted by the non-functioning controller. If the Visual Basic test is successful, the problem lies in the controller.

STATUS

Microsoft has confirmed that this is a problem in the product versions 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

Developers who have used the Class Wizard in Microsoft Visual C++ to generate wrapper classes to automate Microsoft Excel may also encounter this problem if they generated the classes from an older type library. Class Wizard will read the type library and call IDispatch::Invoke with whichever flag is appropriate. When used with an older type library, it will see that the collection accessors are implemented as methods, so it will use the DISPATCH_METHOD flag when it calls these functions. The solution is the same. Logically OR DISPATCH_METHOD with DISPATCH_PROPERTYGET for the wFlags parameter in the Dispatch helper function calls. This will result in IDispatch::Invoke being properly called by the wrapper classes.

REFERENCES

For additional information, please see the following:

"Ole2 Programmer's Reference," Volume 2, Chapter 5, "Dispatch Methods", p. 112

For additional information, please see the following article(s) in the Microsoft Knowledge Base:

   ARTICLE-ID: Q141759
   TITLE     : SAMPLE: XLCLIENT: Automation Client for Excel


Additional query words: XLClient
Keywords : kbinterop kbtool kbbug
Technology : kbole
Version : 2.0 2.2 4.0 4.1 4.2 4.2 5.0
Platform : NT WINDOWS
Issue type : kbbug


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