|
|
Question : Reference problem with C# addin and Excel 2003
|
|
I've created a C# addin with a reference to the Excel 2000 object model.
In the OnConnection event I cast the application object to that of a Excel.Application.
Then in the OnStartUpComplete event I pass this object into a seperate class that attaches event handlers to the NewWorkbook, WorkbookOpen, and WorkbookActivate events of the Excel.Application object, attaches a menu item in the tools menu, and opens windows forms when the menu item is clicked. Right now these events are just returning the Workbook name for the workbook that fired the event. Later on I will need to refresh charts and data from a server in the correct workbook.
I have code in the Connect class that checks to see if the object is being set properly (try catch blocks with message boxes reporting any errors) and a few message boxes telling me where I'm at (before if, before object cast, etc.)
The problem is I have to support Excel 2000, Xp (2002), and 2003. I thought that if I referenced the Excel 2000 object model I would be ok as the other two should be backwards compatible. Unfortunately, while everything works fine in 2000 (the workbook name is being displayed correctly in a message box for all events), 2003 errors out and doesn't even attach my addin to Excel when I include my class that attaches the events. Not even the "Hello World!" message that is the first line of code in the OnConnection event fires.
Any help on this would be great, right now I'm thinking that I will have to either only support 2003 or write some crazy code that switches between the appropriate dlls at run time.
|
Answer : Reference problem with C# addin and Excel 2003
|
|
Hi,
First of all I have only experience with VB.NET & Excel and it have already been giving me grey hair...
Second, I would prefer to use VB 6.0 or in Your case C++ instead of C#...
However, without going further in my critisism on the present situation You may check out the following articles:
Since MS do not provide any PIA's for version 2000 You need to create them and add them to the project which, at least what I can understand, should give You the possibility to also access 2002 and 2003 as wanted:
Creating an Excel Spreadsheet and Adding Data to It Programmatically (for C#) http://www.programmersheaven.com/articles/arun/excel.htm
How To Build an Office COM Add-in by Using Visual C# .NET http://support.microsoft.com/kb/302901
Binding for Office automation servers with Visual C# .NET http://support.microsoft.com/kb/302902/EN-US/
Let me know how it progress and how You hopefully manage to create a workable solution :-)
Kind regards, Dennis
|
|
|
|
|