Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


View products that this article applies to.

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.

↑ Back to the top


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.

↑ Back to the top


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.

↑ Back to the top


Status

This behavior is by design.

↑ Back to the top


References

For more information, click the following article numbers to view the articles in the Microsoft Knowledge Base:
178474 How to build an add-in (XLL) for Excel using Visual C++
143466 Macro97.exe file available on online services

↑ Back to the top


Keywords: KB301443, kbprb, kbautomation

↑ Back to the top

Article Info
Article ID : 301443
Revision : 8
Created on : 10/12/2007
Published on : 10/12/2007
Exists online : False
Views : 381