PRB: Automation Calls to Excel from an XLL May Fail or Return Unexpected Results (301443)



The information in this article applies to:

  • Microsoft Office Excel 2003
  • Microsoft Excel 2002
  • Microsoft Excel 2000
  • Microsoft Excel 97 for Windows

This article was previously published under Q301443

SYMPTOMS

If an XLL that is loaded in Excel attempts to automate Excel by using its Visual Basic for Applications Object Model, rather than the Excel4() C API for which XLLs were designed, method calls may return unexpected results, or may crash altogether.

CAUSE

A function that is defined in an XLL can be called under three circumstances:
  1. During the recalculation of a workbook
  2. As the result of Excel's Function Wizard being called on to help with the XLL function
  3. As the result of a VBA macro calling Excel's Application.Run Automation method
Under the first two circumstances, Excel's Object Model does not expect, and is not prepared for, incoming Automation calls. Consequently, unexpected results or crashes may occur.

RESOLUTION

In order to ensure that they function properly, no Automation calls should be made from an XLL. Instead, all commands to Excel from the XLL should be sent using the Excel4() C API. For more information on writing XLLs, see the "References" section.

STATUS

This behavior is by design.

REFERENCES

For additional information, click the article numbers below to view the articles in the Microsoft Knowledge Base:

178474 HOWTO: Build an Add-in (XLL) for Excel Using Visual C++

143466 Macro97.exe File Available on Online Services

152152 FRMWRK32.EXE: Updated Generic.xll Template for Excel


Modification Type:MajorLast Reviewed:12/12/2003
Keywords:kbAutomation kbprb KB301443