Word Embedded Spreadsheet Error

285 views
Skip to first unread message

Mad1523

unread,
Mar 30, 2011, 1:10:47 AM3/30/11
to Excel-DNA
Hey guys,

I found an issue when you try to edit an embedded Excel 2007
spreadsheet in Word while an exceldna addin is loaded. When I have an
excel addin (C# dll) that hooks the event WorkbookBeforeClose, and I
try to right click on embeded spreadsheet in Word 2007 and click Edit,
I get a combination of these errors:

"The program used to create this object is Excel. That program is not
installed on your computer. To edit this object, you must install a
program that can open the object."

or

"Microsoft Office Word can't start the application required to open
this object. An error occurred and this feature is no longer
functioning properly. Would you like to repair this feature now?"

When I comment out the hook of the WorkbookBeforeClose event in my
addin and perform the same procedure, I'm able to edit the embedded
spreadsheets in Word. This happens even if there is no code in my
event handler function and even when the entire add-in dll only
implements a blank AutoOpen, AutoClose, and the handler function.

Has anyone else encountered this problem?

Govert van Drimmelen

unread,
Mar 30, 2011, 4:25:04 AM3/30/11
to Excel-DNA
Hi,

It looks like this problem is not unique to Excel-DNA:
http://blogs.msdn.com/b/vsofficedeveloper/archive/2008/04/11/excel-ole-embedding-errors-with-managed-addin.aspx
http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/74aaea5b-a14f-4b60-8683-b2c3831120e1/

The first link also suggests a complicated-looking workaround.

Let us know what you find.

-Govert

Mad1523

unread,
Apr 4, 2011, 4:20:20 AM4/4/11
to Excel-DNA
For some reason, the problem only occurs when I hook the
WorkbookBeforeClose event. Nonetheless, I solved the problem with the
following:

1) Release your reference to
ExcelDna.Integration.ExcelDnaUtil.Application in the AutoClose event:

public void AutoClose()
{

System.Runtime.InteropServices.Marshal.ReleaseComObject(YOUR_Application_OBJECT);
}

2) Release the com object provided as a parameter to each event:

private static void Event_WorkbookBeforeClose(Workbook Wb, ref bool
Cancel)
{
// ... code ...
System.Runtime.InteropServices.Marshal.ReleaseComObject(Wb);
}
private static void Event_WorkbookActivate(object obj)
{
// ... code ...
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
}


I hope this helps anyone else that encounters this problem. Keep up
the good work Govert.


On Mar 30, 1:25 am, Govert van Drimmelen <gov...@icon.co.za> wrote:
> Hi,
>
> It looks like this problem is not unique to Excel-DNA:http://blogs.msdn.com/b/vsofficedeveloper/archive/2008/04/11/excel-ol...http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/74aaea5b-a1...
>
> The first link also suggests a complicated-looking workaround.
>
> Let us know what you find.
>
> -Govert
>
> On Mar 30, 7:10 am, Mad1523 <mad1...@gmail.com> wrote:
>
>
>
> > Hey guys,
>
> > I found an issue when you try to edit an embedded Excel 2007
> > spreadsheet in Word while an exceldna addin is loaded. When I have an
> > excel addin (C# dll) that hooks the event WorkbookBeforeClose, and I
> > try to right click on embeded spreadsheet in Word 2007 and click Edit,
> > I get a combination of these errors:
>
> > "The program used to create this object is Excel. That program is not
> > installed on your computer. To edit this object, you must install a
> > program that can open the object."
>
> > or
>
> > "Microsoft Office Word can't start the application required to open
> > this object. An error occurred and this feature is no longer
> > functioning properly. Would you like to repair this feature now?"
>
> > When I comment out the hook of the WorkbookBeforeClose event in my
> > addin and perform the same procedure, I'm able to edit the embedded
> > spreadsheets in Word. This happens even if there is no code in my
> > event handler function and even when the entire add-in dll only
> > implements a blank AutoOpen, AutoClose, and the handler function.
>
> > Has anyone else encountered this problem?- Hide quoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages