Trendlines.Add method (Word)

Creates a new trendline.

Syntax

expression.Add (Type, Order, Period, Forward, Backward, Intercept, DisplayEquation, DisplayRSquared, Name)

expression A variable that represents a 'Trendlines' object.

Parameters

Name Required/Optional Data type Description
Type Optional XlTrendlineType One of the enumeration values that specifies the trendline type. The default is xlLinear.
Order Optional Variant The trendline order. Required ifType is set to xlPolynomial. If specified, the value must be an integer from 2 through 6.
Period Optional Variant The trendline period. Required ifType is set to xlMovingAvg. If specified, the value must be an integer greater than 1 and less than the number of data points in the series to which you are adding a trendline.
Forward Optional Variant The number of periods (or units on a scatter chart) that the trendline extends forward.
Backward Optional Variant The number of periods (or units on a scatter chart) that the trendline extends backward.
Intercept Optional Variant The trendline intercept. If specified, the value must be a double-precision floating-point number. If omitted, the intercept is automatically set by the regression, and the InterceptIsAuto property of the resulting Trendline object is set to True. This parameter is applicable only ifType is set to xlExponential, xlLinear, or xlPolynomial.
DisplayEquation Optional Variant True to display the equation of the trendline on the chart (in the same data label as the R-squared value). The default is False.
DisplayRSquared Optional Variant True to display the R-squared value of the trendline on the chart (in the same data label as the equation). The default is False.
Name Optional Variant The name of the trendline. If omitted, Microsoft Word generates a name, and the NameIsAuto property of the resulting Trendline object is set to True.

Return value

A Trendline object that represents the new trendline.

Example

The following example creates a new linear trendline for the first chart in the active document.

With ActiveDocument.InlineShapes(1) 
    If .HasChart Then 
        .Chart.SeriesCollection(1).Trendlines.Add 
    End If 
End With

See also

Trendlines Object

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.