Home » excel » How to insert an excel chart into Word using AddOLEObject

How to insert an excel chart into Word using AddOLEObject

Posted by: admin May 14, 2020 Leave a comment

Questions:

I’m trying to create a linked OLE Object in a Word document using VB.Net.

Existing code uses InlineShapes.AddOLEObject(FileName:=”abc.xlsx”, LinkToFile:=True, Range:=Some Word Range) to insert a worksheet into a Word document.

I need more control than this. To select a range of cells I’ve found that extra information after the filename can be useful, for example: FileName:=”abc.xlsx!sheet1!R1C1:R20C5″

Is there a way to specify a specific chart within a worksheet? So can I specify the second chart on the worksheet as the object to link to?

Thanks.

How to&Answers:

Thanks for your help Mark.

I eventually figured out that if the Chart is in it’s own sheet, rather than an object in Sheet1, then the AddOLEObject code works correctly with the following setting:

FileName:=”abc.xlsx!Chart1″

I’m happy with this solution.

Answer:

A chart will either be a whole worksheet so address as per your sheet1 e.g. abc.xlsx!sheet1 or an object on a sheet so use the object name e.g. abc.xlsx!sheet1!chart_object