How to insert an excel chart into Word using AddOL

2019-02-16 00:38发布

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.

2条回答
Evening l夕情丶
2楼-- · 2019-02-16 00:56

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

查看更多
我命由我不由天
3楼-- · 2019-02-16 00:57

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.

查看更多
登录 后发表回答