Microsoft KB Archive/284876

= Excel fails when Automation add-In loads =

Article ID: 284876

Article Last Modified on 2/9/2007

-

APPLIES TO


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

-



This article was previously published under Q284876



SYMPTOMS
When Microsoft Excel loads an Automation add-in during cell edit mode, Excel fails. This problem only occurs with Automation add-ins that have been Demand Loaded into Excel.



CAUSE
This problem can occur when an add-in loads if the add-in displays a form or dialog box, or if the add-in makes an Automation request to Excel that tries to change the state of Excel. The following list includes samples of Automation requests that may cause Excel to fail when it is called while an Automation add-in loads during cell edit mode:   Programmatically change the current selection. For example: Application.ActiveSheet.Range(&quot;A1&quot;).Select   Call a property or method of an item in the Windows collection. For example: Application.ActiveWindow.Zoom = 200   Change an Excel setting such as the calculation mode. For example: Application.CalculationMode = xlManual 

All of these items are examples of code attempts to change the Excel environment, a workbook, or a worksheet; these types of actions are not permitted while in edit mode.



RESOLUTION
Do not try the above-mentioned actions while your add-in loads. Add-in methods that are called during the load include the Initialize method and, if your Automation add-in implements the IDTExtensibility2 interface, the OnConnection and OnStartupComplete methods as well.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce Problem
 Start a new ActiveX DLL project in Visual Basic.</li> From the Project menu, click Project1 Properties. Change the Project Name to TestAddIn, and then click OK.</li>  Add the following code to the code module for Class1: Private Sub Class_Initialize MsgBox &quot;Class_Initialize&quot; End Sub </li> Build TestAddIn.dll.</li> In Excel, start a new workbook.</li> In Microsoft Office Excel 2003 or in Microsoft Excel 2002, follow these steps: <ol style="list-style-type: lower-alpha;"> On the Tools menu, point to Add-Ins, and then click Automation.</li> In the list, click TestAddIn.Class1, and then click OK.</li> In the Add-Ins dialog box, click OK.</li></ol>

In Microsoft Office Excel 2007, follow these steps: <ol style="list-style-type: lower-alpha;"> Click the Microsoft Office Button, and then click Excel Options.</li> Click the Add-Ins tab.</li> In the Manage list, click Excel Add-ins, and then click Go.</li> In the Add-Ins dialog box, click Automation.</li> In the list, click TestAddin.Class1, and then click OK.</li> Click OK.</li></ol> </li> Type =a in any cell. A message box with the text &quot;Class_Initialize&quot; appears.</li> Click OK to dismiss the message box. After a few seconds, Excel fails.</li></ol>

<div class="references_section">