Class Trendline (Word VBA)

The class Trendline represents a trendline in a chart.

The main procedures of class Trendline are Delete, Select and Trendlines.Add


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

Dim trnln as Trendline
Set trnln = ActiveDocument.Background.Chart.FullSeriesCollection(1).Trendlines(Index:=1)

The following procedures can be used to set variables of type Trendline: Trendlines.Add, Trendlines.Item and Series.Trendlines

For Each

Here is an example of processing the Trendline items in a collection.

Dim trnln As Trendline
For Each trnln In ActiveDocument.Background.Chart.FullSeriesCollection(1).Trendlines()
Next trnln


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

Format with its procedures Border, ClearFormats and Format
Display/Show with its procedures DisplayEquation and DisplayRSquared


These are the main methods of the Trendline class

Delete - Deletes the object.


Select - Selects the object.


Trendlines.Add - Creates a new trendline.

Dim trnln As Trendline
Set trnln = ActiveDocument.Background.Chart.FullSeriesCollection(1).Trendlines.Add()


Backward2 returns or sets the number of periods (or units on a scatter chart) that the trendline extends backward.

ActiveDocument.Background.Chart.FullSeriesCollection(1).Trendlines(1).Backward2 =

DataLabel returns the data label that is associated with the trendline.

Dim dtlDataLabel As DataLabel
Set dtlDataLabel = ActiveDocument.Background.Chart.FullSeriesCollection(1).Trendlines(1).DataLabel

Forward2 returns or sets the number of periods (or units on a scatter chart) that the trendline extends forward.

ActiveDocument.Background.Chart.FullSeriesCollection(1).Trendlines(1).Forward2 =

Index returns the index number of the object within the collection of similar objects.

Dim lngIndex As Long
lngIndex = ActiveDocument.Background.Chart.FullSeriesCollection(1).Trendlines(1).Index

Intercept returns or sets the point where the trendline crosses the value axis.

ActiveDocument.Background.Chart.FullSeriesCollection(1).Trendlines(1).Intercept =

InterceptIsAuto true if the point where the trendline crosses the value axis is automatically determined by the regression.

ActiveDocument.Background.Chart.FullSeriesCollection(1).Trendlines(1).InterceptIsAuto = True

Name returns or sets name of the object.

ActiveDocument.Background.Chart.FullSeriesCollection(1).Trendlines(1).Name =

NameIsAuto true if Microsoft Word automatically determines the name of the trendline.

ActiveDocument.Background.Chart.FullSeriesCollection(1).Trendlines(1).NameIsAuto = True

Order returns or sets the trendline order (an integer greater than 1) when the trendline type is xlPolynomial.

ActiveDocument.Background.Chart.FullSeriesCollection(1).Trendlines(1).Order =

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

Dim objParent As Object
Set objParent = ActiveDocument.Background.Chart.FullSeriesCollection(1).Trendlines(1).Parent

Period returns or sets the period for the moving-average trendline.

ActiveDocument.Background.Chart.FullSeriesCollection(1).Trendlines(1).Period =

Type returns or sets the trendline type.

ActiveDocument.Background.Chart.FullSeriesCollection(1).Trendlines(1).Type = xlExponential

Trendlines.Count returns the number of objects in the collection.

Dim lngCount As Long
lngCount = ActiveDocument.Background.Chart.FullSeriesCollection(1).Trendlines.Count

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

Dim objParent As Object
Set objParent = ActiveDocument.Background.Chart.FullSeriesCollection(1).Trendlines.Parent