Thread: [Solved] Updating tables in Word
View Single Post
 
Old 04-11-2025, 07:40 AM
Italophile Italophile is offline Windows 11 Office 2021
Expert
 
Join Date: Mar 2022
Posts: 554
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

The first mistake you have made is using Late Binding.
There is no value to using late binding in this instance. The only advantage to late binding is version independence, i.e. you can write code in a newer version and it will theoretically work in an older one. But that advantage is lost unless you also use late binding for the host application code as Office is usually installed as a package. It is better to use early binding when working with other Office applications and reserve late binding for other commonly used libraries, e.g. ADO or XML.

By adding a reference to the Excel library (Tools | References) and declaring the object variables with their correct types (eg. Dim chartObj As xl.Chart) you get the benefit of IntelliSense.

Instead of
Code:
chartObj.Copy
What you need is
Code:
chartObj.ChartArea.Copy
When pasted this will give you a linked chart but the link can be broken by adding something like
Code:
bmRange.InlineShapes(1).Chart.ChartData.Activate
bmRange.InlineShapes(1).Chart.ChartData.BreakLink
Reply With Quote