Microsoft KB Archive/301443

= Automation calls to Excel from an XLL may fail or return unexpected results =

Article ID: 301443

Article Last Modified on 10/12/2007

-

APPLIES TO


 * Microsoft Office Excel 2007
 * Microsoft Office Excel 2003
 * Microsoft Excel 2002 Standard Edition
 * Microsoft Excel 2000 Standard Edition
 * Microsoft Excel 97 Standard Edition

-



This article was previously published under Q301443



SYMPTOMS
If an XLL that is loaded in Microsoft Office 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 &quot;References&quot; section.



STATUS
This behavior is by design.

