Microsoft KB Archive/834614

= The Visual Studio .NET or Visual Studio 2005 client application cannot catch the events that are raised by an Office Spreadsheet 11.0 ActiveX control =

Article ID: 834614

Article Last Modified on 11/27/2007

-

APPLIES TO


 * Microsoft Visual Basic 2005
 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition
 * Microsoft Visual C# 2005 Express Edition
 * Microsoft Visual C# .NET 2003 Standard Edition
 * Microsoft Visual C# .NET 2002 Standard Edition

-





SUMMARY
The Microsoft Visual Studio .NET or Visual Studio 2005 client application cannot catch the events that are raised by an existing ActiveX control (Microsoft Office Spreadsheet 11.0).



SYMPTOMS
When the Microsoft Office Spreadsheet 11.0 ActiveX control raises events, managed code cannot catch these events.



CAUSE
The IChartInterface interface of the OWC11.dll file has dispatch identifiers (DISPIDs) on its methods. When you derive the event listener class from the IChartInterface interface, the overridden methods do not support the DISPIDs of the IChartInterface interface. When the Microsoft Office Spreadsheet 11.0 tries to raise the event, the event listener class cannot find the DISPIDs.



RESOLUTION
To resolve this problem, follow these steps:  Run the AxImp.exe tool on the OWC11.dll file.  Locate the OWC11.dll file. The OWC11.dll file is a DLL for the Microsoft Office Spreadsheet 11.0 ActiveX control. The OWC11.dll file is typically located in the following folder: C:\Program Files\Common Files\Microsoft Shared\Web Components\11. Click Start, click Run, and then type cmd in the Open box. At the command prompt, locate the OWC11.dll file. Type aximp /source OWC11.dll at the command prompt. You notice that the AxOWC11.dll file and the AxOWC11.cs file are generated and are placed in the same folder where this command is executed.

The AxImp.exe file converts the whole ActiveX control type library and produces a set of assemblies that contain the common language runtime metadata and control implementation for the types that are defined in the original type library.</ol> </li> Modify the AxOWC11.cs file. To do this, add the code in the following steps to modify all the Control classes and the corresponding EventMulticaster classes in the source file that is generated. <ol style="list-style-type: lower-alpha;">  Set the ToolboxItem attribute to true in the generated class file. To do this Add the following code before the Control classes: [System.ComponentModel.ToolBoxItem(True)] The Control classes are as follows: <ul> AxChartSpace</li> AxSpreadsheet</li> AxDataSourceControl</li> AxRecordNavigationControl</li> AxPivotTable</li></ul> </li>  Add the following code above the EventMulticaster classes: [System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)] The EventMulticaster classes are as follows: <ul> AxChartSpaceEventMulticaster</li> AxSpreadsheetEventMulticaster</li> AxDataSourceControlEventMulticaster</li> AxRecordNavigationControlEventMulticaster</li> AxPivotTableEventMulticaster</li></ul> </li></ol> </li> Compile the modified AxOWC11.cs file. <ol> Locate, and then copy the assemblies that are referenced in the AxOWC11.cs file to a folder. The referenced assemblies are as follows: <ul> Microsoft.Office.Interop.Owc11.dll</li> <li>Adodb.dll</li> <li>Mscomctl.dll</li> <li>Msdatasrc.dll</li></ul> </li> <li>At the command prompt, change the directory to C:\Temp.</li> <li> To compile the AxOWC11.cs file, type the following command at the command prompt: csc /t:library /lib:c:\Temp /r:Microsoft.Office.Interop.Owc11.dll;ADODB.dll;MSCOMCTL.DLL;msdatasrc.dll AxOWC11.cs  Note   is a folder that you create in your hard disk drive. This folder contains the referenced assemblies and the AxOWC11.cs file. </li></ol> </li> <li>Test the modified AxOWC11.cs file. <ol style="list-style-type: lower-alpha;"> <li>Start Microsoft Visual Studio .NET or Microsoft Visual Studio 2005.</li> <li>On the File menu, point to New, and then click Project.</li> <li>Under Project Types, click Visual Basic Projects, and then click Windows Application under Templates.

Note In Visual Studio 2005, click Visual Basic under Project Types.</li> <li>On the View menu, click Toolbox.</li> <li>Right-click the toolbox, and then click Add/Remove Items. The Customize Toolbox dialog box appears.

Note In Visual Studio 2005, right-click the toolbox, and then click Choose Items.</li> <li>On the COM Components tab, click to select Microsoft Office Spreadsheet 11.0, and then click OK. The Microsoft Office Spreadsheet 11.0 ActiveX control is added to the toolbox.</li> <li>Add the Microsoft Office Spreadsheet 11.0 ActiveX control to the Form1 form.</li> <li>In Solution Explorer, expand References under the project, and then click AxOWC11.</li> <li>On the View menu, click Remove.</li> <li>Click References under Solution Explorer, and then click Add Reference. The Add Reference dialog box appears.</li> <li>Click Browse, locate and select the AxOWC11.dll file, and then click OK.</li> <li>On the View menu, click Code.</li> <li>Select AxSpreadsheet1 from the box in the Code view window.</li> <li> Select the EndEdit event from the second box in the Code view window. The following procedure is added to the Code view: Private Sub AxSpreadsheet1_EndEdit(ByVal sender As Object, ByVal e As AxMicrosoft.Office.Interop.Owc11.ISpreadsheetEventSink_EndEditEvent) Handles AxSpreadsheet1.EndEdit

End Sub </li> <li> Add the following code to this procedure: MessageBox.Show(&quot;Test EndEdit&quot;) </li></ol> </li> <li>Build and run the application. <ol> <li>On the Build menu, click Build Solution.</li> <li>On the Debug menu, click Start.</li> <li>Edit the cell in the Microsoft Excel spreadsheet that appears, and then click the next cell in the Excel spreadsheet. You receive a dialog box with the following text:

Test EndEdit

</li></ol> </li></ol>

<div class="status_section">

STATUS
This behavior is by design.

<div class="moreinformation_section">

Steps to reproduce the behavior
<ol> <li>Create a Windows application. <ol style="list-style-type: lower-alpha;"> <li>Start Microsoft Visual Studio .NET or Microsoft Visual Studio 2005.</li> <li>On the File menu, point to New and then click Project.</li> <li>Under Project Types, click Visual Basic Projects, and then click Windows Application under Templates.

Note In Visual Studio 2005, click Visual Basic under Project Types.</li></ol> </li> <li>Add the Microsoft Office Spreadsheet ActiveX control to the Form1 form. <ol style="list-style-type: lower-alpha;"> <li>On the View menu, click Toolbox.</li> <li>Right-click the toolbox, and then click Add/Remove Items. The Customize Toolbox dialog box appears.

Note In Visual Studio 2005, right-click the toolbox, and then click Choose Items.</li> <li>On the COM Components tab, click to select Microsoft Office Spreadsheet 11.0, and then click OK. The Microsoft Office Spreadsheet 11.0 ActiveX control is added to the toolbox.</li> <li>Add the Microsoft Office Spreadsheet 11.0 ActiveX control to the Form1 form.</li></ol> </li> <li>Add the code to the EndEdit event. <ol style="list-style-type: lower-alpha;"> <li>On the View menu, click Code.</li> <li>Select AxSpreadsheet1 from the box in the Code view window.</li> <li> Select the EndEdit event from the second box in the Code view window. The following procedure is added to the Code view: Private Sub AxSpreadsheet1_EndEdit(ByVal sender As Object, ByVal e As AxMicrosoft.Office.Interop.Owc11.ISpreadsheetEventSink_EndEditEvent) Handles AxSpreadsheet1.EndEdit

End Sub </li> <li> Add the following code to this procedure: MessageBox.Show(&quot;Test EndEdit&quot;) </li></ol> </li> <li>Build the application, and then and run the application. <ol style="list-style-type: lower-alpha;"> <li>On the Build menu, click Build Solution.</li> <li>On the Debug menu, click Start.</li> <li>Edit the cell in the Excel spreadsheet that appears. Click the next cell of the Excel spreadsheet. The dialog box that indicates that the event is not fired does not appear.</li></ol> </li></ol>

<div class="references_section">