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.
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.