Class Chart (Word VBA)

The class Chart represents a chart in a document.

The main procedures of class Chart are Copy, Delete and Select

Set

To use a Chart class variable it first needs to be instantiated, for example

Dim chr as Chart
Set chr = ActiveDocument.Background.Chart

The following procedures can be used to set variables of type Chart: InlineShape.Chart and Shape.Chart

Themes

Some procedures in this class have been grouped together in themes and are described on separate theme pages

Name with its procedures ChartTitle, HasTitle and SeriesNameLevel
Display/Show with its procedures DisplayBlanksAs, ShowAllFieldButtons, ShowLegendFieldButtons and ShowValueFieldButtons

Methods

These are the main methods of the Chart class

Copy - Not supported for this object.

ActiveDocument.Background.Chart.Copy

Delete - Deletes the object.

ActiveDocument.Background.Chart.Delete

Select - Selects the object.

ActiveDocument.Background.Chart.Select

Other Methods

ApplyDataLabels - Applies data labels to all the series in a chart.

ActiveDocument.Background.Chart.ApplyDataLabels

ApplyLayout - Applies the layouts shown in the ribbon.

Dim lngLayout As Long: lngLayout =  
ActiveDocument.Background.Chart.ApplyLayout Layout:=lngLayout

Axes - Returns a collection of axes on the chart.

Dim axs As Axes
Set axs = ActiveDocument.Background.Chart.Axes()

ChartWizard - Modifies the properties of the given chart. You can use this method to quickly format a chart without setting all the individual properties. This method is noninteractive, and it changes only the specified properties.

ActiveDocument.Background.Chart.ChartWizard

Export - Exports the chart in a graphic format.

Dim strFileName As String: strFileName =  
Dim booExport As Boolean
booExport = ActiveDocument.Background.Chart.Export(FileName:=strFileName)

GetChartElement - Returns information about the chart element at the specified x-coordinate and y-coordinate.

Dim lngx As Long: lngx = 
Dim lngy As Long: lngy = 
Dim lngElementID As Long: lngElementID = 
Dim lngArg1 As Long: lngArg1 = 
Dim lngArg2 As Long: lngArg2 =  
ActiveDocument.Background.Chart.GetChartElement x:=lngx, y:=lngy, ElementID:=lngElementID, Arg1:=lngArg1, Arg2:=lngArg2

SetSourceData - Sets the source data range for the chart.

Dim strSource As String: strSource =  
ActiveDocument.Background.Chart.SetSourceData Source:=strSource

Properties

AutoScaling true if Microsoft Word scales a 3D chart so that it is closer in size to the equivalent 2D chart. The RightAngleAxes property must be True.

ActiveDocument.Background.Chart.AutoScaling = True

BackWall returns an object that allows the user to individually format the back wall of a 3D chart.

Dim wllsBackWall As Walls
Set wllsBackWall = ActiveDocument.Background.Chart.BackWall

BarShape returns or sets the shape used for every series in a 3D bar or column chart.

ActiveDocument.Background.Chart.BarShape = xlBox

CategoryLabelLevel returns or sets an XlCategoryLabel constant that specifies the source level of the chart category labels.

ActiveDocument.Background.Chart.CategoryLabelLevel = xlCategoryLabelLevelAll

ChartArea returns the complete chart area for the chart.

Dim caaChartArea As ChartArea
Set caaChartArea = ActiveDocument.Background.Chart.ChartArea

ChartColor returns or sets an integer that represents the color scheme for the chart.

ActiveDocument.Background.Chart.ChartColor =

ChartData returns information about the linked or embedded data associated with a chart.

Dim cdaChartData As ChartData
Set cdaChartData = ActiveDocument.Background.Chart.ChartData

ChartGroups returns an chartgroups that represents either a single chart group or a collection of all the chart groups in the chart.

Dim cgsChartGroups As ChartGroups
Set cgsChartGroups = ActiveDocument.Background.Chart.ChartGroups

ChartStyle returns or sets the chart style for the chart.

ActiveDocument.Background.Chart.ChartStyle =

ChartType returns or sets the chart type.

ActiveDocument.Background.Chart.ChartType =

DataTable returns the chart data table.

Dim dteDataTable As DataTable
Set dteDataTable = ActiveDocument.Background.Chart.DataTable

DepthPercent returns or sets the depth of a 3D chart as a percentage of the chart width (between 20 and 2000 percent).

ActiveDocument.Background.Chart.DepthPercent =

Elevation returns or sets the elevation, in degrees, of the 3D chart view.

ActiveDocument.Background.Chart.Elevation =

Floor returns the floor of the 3D chart.

Dim flrFloor As Floor
Set flrFloor = ActiveDocument.Background.Chart.Floor

GapDepth returns or sets the distance, as a percentage of the marker width, between the data series in a 3D chart.

ActiveDocument.Background.Chart.GapDepth =

HasAxis returns or sets which axes exist on the chart. Read/write Variant.

ActiveDocument.Background.Chart.HasAxis = True

HasDataTable true if the chart has a data table.

ActiveDocument.Background.Chart.HasDataTable = True

HasLegend true if the chart has a legend.

ActiveDocument.Background.Chart.HasLegend = True

HeightPercent returns or sets the height of a 3D chart as a percentage of the chart width (from 5 through 500 percent).

ActiveDocument.Background.Chart.HeightPercent =

Legend returns the legend for the chart.

Dim lgnLegend As Legend
Set lgnLegend = ActiveDocument.Background.Chart.Legend

Parent returns the parent for the specified object. Read-only object.

Dim objParent As Object
Set objParent = ActiveDocument.Background.Chart.Parent

Perspective returns or sets the perspective for the 3D chart view.

ActiveDocument.Background.Chart.Perspective =

PivotLayout not supported for this object.

Dim objPivotLayout As Object
Set objPivotLayout = ActiveDocument.Background.Chart.PivotLayout

PlotArea returns the plot area of a chart.

Dim paaPlotArea As PlotArea
Set paaPlotArea = ActiveDocument.Background.Chart.PlotArea

PlotBy returns or sets the way columns or rows are used as data series on the chart.

ActiveDocument.Background.Chart.PlotBy = xlColumns

PlotVisibleOnly true if only visible cells are plotted. False if both visible and hidden cells are plotted.

ActiveDocument.Background.Chart.PlotVisibleOnly = True

RightAngleAxes true if the chart axes are at right angles, independent of chart rotation or elevation. Read/write Boolean.

ActiveDocument.Background.Chart.RightAngleAxes = True

Rotation returns or sets the rotation, in degrees, of the 3D chart view (the rotation of the plot area around the z-axis). Read/write Variant.

ActiveDocument.Background.Chart.Rotation =

Shapes returns a collection that represents all the shapes on the chart sheet. Read-only Shapes.

Dim shpsShapes As Shapes
Set shpsShapes = ActiveDocument.Background.Chart.Shapes

ShowAxisFieldButtons returns or sets whether to display axis field buttons on a PivotChart. Read/write. Deprecated.

ActiveDocument.Background.Chart.ShowAxisFieldButtons = True

ShowDataLabelsOverMaximum returns or sets a value that indicates whether to show the data labels when the value is greater than the maximum value on the value axis.

ActiveDocument.Background.Chart.ShowDataLabelsOverMaximum = True

ShowReportFilterFieldButtons returns or sets whether to display the report filter field buttons on a PivotChart. Read/write. Deprecated.

ActiveDocument.Background.Chart.ShowReportFilterFieldButtons = True

SideWall returns a Walls object that allows the user to individually format the side wall of a 3D chart.

Dim wllsSideWall As Walls
Set wllsSideWall = ActiveDocument.Background.Chart.SideWall

Walls returns the walls of the 3D chart.

Dim wllsWalls As Walls
Set wllsWalls = ActiveDocument.Background.Chart.Walls