Microsoft KB Archive/241861

= BUG: ATL Control in Office Document Prevents Another Control's Events from Working =

Article ID: 241861

Article Last Modified on 1/25/2007

-

APPLIES TO


 * Microsoft Excel 2000 Standard Edition
 * Microsoft Excel 2002 Standard Edition
 * Microsoft Excel 97 Standard Edition
 * Microsoft Word 2002 Standard Edition
 * Microsoft Word 2000 Standard Edition
 * Microsoft Word 97 Standard Edition
 * Microsoft PowerPoint 2002 Standard Edition
 * Microsoft PowerPoint 2000 Standard Edition
 * Microsoft PowerPoint 97 Standard Edition
 * Microsoft ActiveX Template Library 2.0
 * Microsoft ActiveX Template Library 3.0

-



This article was previously published under Q241861



SYMPTOMS
An ATL Control inserted into an Office 97, Office 2000, or Office XP document (that is, an Excel spreadsheet, PowerPoint presentation, or Word document) causes VBA to not receive events for other controls in the same document. The other controls may fire events, but the VBA code in the event handlers will not run. If the ATL control is removed, events for the other controls work as expected.



CAUSE
When a control is inserted into a document, VBA checks for an outgoing event interface in the type library for the control. If an outgoing event interface is not supplied, it effects the behavior of event handling for the rest of the controls in the document.



RESOLUTION
For Visual Basic applications to function properly, an outgoing event interface must appear in the control's coclass definition. The event interface does not have to be used or implemented, but the even interface must be in the type library.

By default, when you create a new ATL control, Full or Composite, an event interface is not generated if the "Support Connection Points" checkbox is not selected under the Attributes tab from the ATL Object Wizard.

If an event interface was not added with the help of the ATL Object Wizard, you will need to add the event interface to the control manually. You can do this by manually editing the wizard generated IDL code for the ATL control.

The following two code snippets need to be added to the IDL code: //Add this before the library block in your IDL code //Begin new code [     uuid(DC2EF6F1-136F-11d3-8C6C-00C04F542A77), helpstring("IUseATLInExcelEvents Interface"), ]   dispinterface IUseATLInExcelEvents {   }; //End new code //You need to update the coclass to show an event interface //Just add the code below marked with //Begin new code and //End new code. //The rest of the code was just provided as a reference point on where //to add the new code. [   uuid(6734BB80-136B-11D3-8C6C-00C04F542A77), version(1.0), helpstring("ATLVBATest 1.0 Type Library") ] library ATLVBATESTLib {   importlib("stdole32.tlb"); importlib("stdole2.tlb");

[       uuid(6734BB8D-136B-11D3-8C6C-00C04F542A77), helpstring("ATLVBA2 Class") ]   coclass ATLVBA2 {       [default] interface IUseATLInExcel; //Add the following line to any coclasses in the IDL file that are controls //and do not have a default, source interface. //Begin new code [default, source] dispinterface IUseATLInExcelEvents; //End new code }; }; Once the control is rebuilt and re-registered, it should behave correctly when inserted into Excel. If it still does not behave correctly, you may want to look at the the following KB article:

185473 Changes to Custom ActiveX Controls Are Not Used



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

