Class ChartData (Word VBA)

The class ChartData represents access to the linked or embedded data associated with a chart. To use a ChartData class variable it first needs to be instantiated, for example


Dim cda as ChartData
Set cda = ActiveDocument.Background.Chart.ChartData

Activate

Activates the first window of the workbook associated with the chart.

If the chart is linked to a Microsoft Excel workbook, this method does not run any Auto_Activate or Auto_Deactivate macros that might be attached to the workbook (use the RunAutoMacros method to run those macros).


With ActiveDocument.InlineShapes(1) 
 If .HasChart Then 
 .Chart.ChartData.Activate 
 .Chart.ChartData.Workbook. _ 
 Worksheets("Sheet1").Range("B1:B5").Copy 
 .Chart.Paste 
 End If 
End With 

ActivateChartDataWindow

Opens a Excel data grid window that contains the full source data for the specified chart.

If the data grid window is already open, this method has no effect. The ActivateChartDataWindow method differs from the ChartData.Activate method in that the former opens the chart in an Excel window within Word, with the Excel ribbon unavailable, whereas the latter opens a full version of Excel, with the ribbon available.



Public Sub ActivateChartDataWindow_Example()

    ThisDocument.Shapes(1).Chart.ChartData.ActivateChartDataWindow

End Sub

Removes the link between the data for a chart and a Microsoft Excel workbook.

Calling this method sets the IsLinked property of the ChartData object to False.


With ActiveDocument.InlineShapes(1) 
 If .HasChart Then 
 .Chart.ChartData.Activate 
 .Chart.ChartData.BreakLink 
 End If 
End With

IsLinked

True if the data for the chart is linked to an external Microsoft Excel workbook.

Using the BreakLink method to remove the link to an Excel workbook sets this property to False.


With ActiveDocument.InlineShapes(1) 
 If .HasChart Then 
 With .Chart.ChartData 
 If .IsLinked Then 
 .BreakLink 
 Else 
 .Activate 
 End If 
 End With 
 End If 
End With

Workbook

Returns the workbook that contains the chart data associated with the chart.


With ActiveDocument.InlineShapes(1) 
 If .HasChart Then 
 .Chart.ChartData.Activate 
 .Chart.ChartData.Workbook. _ 
 Worksheets("Sheet1").Range("B1:B5").Copy 
 .Chart.Paste 
 End If 
End With