Class Trendlines (Word VBA)
The class Trendlines represents a collection of all the Trendline objects for the specified series. To use a Trendlines class variable it first needs to be instantiated, for example
Dim trns as Trendlines
Set trns = ActiveDocument.Background.Chart.FullSeriesCollection(1).Trendlines()
For Each
Here is an example of processing the Trendlines items in a collection.
Dim trnln As Trendline
For Each trnln In ActiveDocument.Background.Chart.FullSeriesCollection(1).Trendlines()
Next trnln
Add
Creates a new trendline.
Add (Type, Order, Period, Forward, Backward, Intercept, DisplayEquation, DisplayRSquared, Name)
With ActiveDocument.InlineShapes(1)
If .HasChart Then
.Chart.SeriesCollection(1).Trendlines.Add
End If
End With
Arguments
Optional arguments
The following arguments are optional
Type (XlTrendlineType) - One of the enumeration values that specifies the trendline type. The default is xlLinear.
Possible values are
xlExponential | Uses an equation to calculate the least squares fit through points (for example, y=ab^x) . |
xlLinear | Uses the linear equation y = mx + b to calculate the least squares fit through points. |
xlLogarithmic | Uses the equation y = c ln x + b to calculate the least squares fit through points. |
xlMovingAvg | Uses a sequence of averages computed from parts of the data series. The number of points equals the total number of points in the series minus the number specified for the period. |
xlPolynomial | Uses an equation to calculate the least squares fit through points (for example, y = ax^6 + bx^5 + cx^4 + dx^3 + ex^2 + fx + g). |
xlPower | Uses an equation to calculate the least squares fit through points (for example, y = ax^b). |
Order (XlTrendlineType) - The trendline order. Required ifType is set to xlPolynomial. If specified, the value must be an integer from 2 through 6.
Possible values are
xlExponential | Uses an equation to calculate the least squares fit through points (for example, y=ab^x) . |
xlLinear | Uses the linear equation y = mx + b to calculate the least squares fit through points. |
xlLogarithmic | Uses the equation y = c ln x + b to calculate the least squares fit through points. |
xlMovingAvg | Uses a sequence of averages computed from parts of the data series. The number of points equals the total number of points in the series minus the number specified for the period. |
xlPolynomial | Uses an equation to calculate the least squares fit through points (for example, y = ax^6 + bx^5 + cx^4 + dx^3 + ex^2 + fx + g). |
xlPower | Uses an equation to calculate the least squares fit through points (for example, y = ax^b). |
Period (XlTrendlineType) - 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.
Possible values are
xlExponential | Uses an equation to calculate the least squares fit through points (for example, y=ab^x) . |
xlLinear | Uses the linear equation y = mx + b to calculate the least squares fit through points. |
xlLogarithmic | Uses the equation y = c ln x + b to calculate the least squares fit through points. |
xlMovingAvg | Uses a sequence of averages computed from parts of the data series. The number of points equals the total number of points in the series minus the number specified for the period. |
xlPolynomial | Uses an equation to calculate the least squares fit through points (for example, y = ax^6 + bx^5 + cx^4 + dx^3 + ex^2 + fx + g). |
xlPower | Uses an equation to calculate the least squares fit through points (for example, y = ax^b). |
Forward (Long) - The number of periods (or units on a scatter chart) that the trendline extends forward.
Backward (Long) - The number of periods (or units on a scatter chart) that the trendline extends backward.
Intercept (Trendline) - 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.
DisplayEquation - Boolean
DisplayRSquared - Boolean
Name - String
Count
Returns the number of objects in the collection.
Dim lngCount As Long
lngCount = ActiveDocument.Background.Chart.FullSeriesCollection(1).Trendlines.Count
Item
Returns a single Trendline object from the collection.
Item (Index)
Index: The index number for the object.
With ActiveDocument.InlineShapes(1)
If .HasChart Then
With .Chart.SeriesCollection(1).Trendlines.Item(1)
.Forward = 5
.Backward = .5
End With
End If
End With