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!

Could you be so kind to give me a repro steps for this issue with a
environment description, for example OS version, visual studio version and
others? I will test this for you.

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

c duden

Hello Wei-Dong:

No problem,

My current build: VS.NET 2k3, Office 2K, Win XP Pro:

I have figured out the problem, it doesn't like the path I am passing in
(same path I am using in Word and Powerpoint). I will need to investigate.

Thanks.
 
C

C Duden

Figured out what the issue was this morning -- some
escape characters in the path. These worked fine in Word
and Powerpoint but Excel didn't like them one bit.
Unfortunately the error message that is returned is
pretty generic so it was a trial and error approach to
figure out the problem.

Thanks for the help.
Cduden
-----Original Message-----
Hi duden,

Thank you for posting in MSDN managed newsgroup!

Based on my test, I haven't reproed this issue. For your convenience, I
build one sample project for you. You can modify the test.doc path in the
source code and test this in your winxp box. It will be greatly appreciated
you tell me the result.

Please feel free to let me know if you have any further questions. I'll
stand by to be some of assistance.

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

Wei-Dong Xu [MSFT]

Hi Duden,

Thank you for replying!

It is my pleasure to be some of service!

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