Excel OLE linking

C

c duden

Excel won't allow documents to be linked to a worksheet in office 2000 when
using C# to create an add-in.

The following code snippets are what was used in the attempts
(there are more permutations of parameters, but for brevity...):

// one - based on code from Matt Reynolds' website
Excel.Worksheet active =
(Excel.Worksheet)excelApp.ActiveWorkbook.ActiveSheet;
((Excel.OLEObjects)active.OLEObjects(Type.Missing)).Add(
classtype, path, true, false, Type.Missing,
Type.Missing, Type.Missing, 10.0F, 10.0F, 400.0F, 150.0F).Select(false);

// two
Excel.Worksheet active =
(Excel.Worksheet)excelApp.ActiveWorkbook.ActiveSheet;
((Excel.OLEObjects)active.OLEObjects(Type.Missing)).Add(
classtype, path, true, false, Type.Missing,
Type.Missing, Type.Missing, 10.0F, 10.0F, 400.0F, 150.0F);

// three
Excel.Worksheet active =
(Excel.Worksheet)excelApp.ActiveWorkbook.ActiveSheet;
((Excel.OLEObjects)active.OLEObjects(Type.Missing)).Add(
Type.Missing, path, true, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, 10.0F, 10.0F, 400.0F, 150.0F);


// four
Excel.Application ExcelApp = (Excel.Application)mApplication;
Excel.WorkbookClass Book = (Excel.WorkbookClass)ExcelApp.ActiveWorkbook;
Excel.Worksheet Sheet = (Excel.Worksheet)Book.ActiveSheet;

Excel.Shape Shp = Sheet.Shapes.AddOLEObject(Type.Missing, path, true,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing);


All examples throw exceptions that state that linking cannot be performed,
the object cannot be inserted, or that the Add method failed.

Considering that the code to accomplish this in VBA is quite simple, this
problem is perplexing.
ActiveSheet.OLEObjects.Add(Filename:= _
"C:\Documents and Settings\jhamilton\My Documents\Test1.doc",
Link:=True, _
DisplayAsIcon:=False).Select

I've examined the interop assemblies to ensure that all events are public,
which I don't think is problem, but it was worth a shot. All research led me
to the above solutions, all of which failed.

Does anyone have any insight into this or an example of this working?
Thanks.
 
W

Wei-Dong Xu [MSFT]

Hi duden,

Thank you for posting in MSDN managed newsgroup!

I have replied you for this issue in
microsoft.public.office.developer.automation.

Thank you for using Microsoft NewsGroup!

Wei-Dong Xu
Microsoft Product Support Services
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top