Range.ComputeStatistics method (Word)

Returns a Long that represents a statistic based on the contents of the specified range.

Syntax

expression. ComputeStatistics( _Statistic_ )

expression Required. A variable that represents a Range object.

Parameters

Name Required/Optional Data type Description
Statistic Required WdStatistic The type of statistic to compute.

Remarks

Some of the constants listed above may not be available to you, depending on the language support (U.S. English, for example) that you've selected or installed.

The Statistic returned for Table.Cell Range will be inaccurate due to the end-of-cell marker interfering with the Statistic. Truncating the Range to remove the end-of-cell-marker will result in the correct Statistic value.

Set cell = Documents("Report.doc").Tables(1).Cell(1, 1)
Set myRange = cell.Range
lineCount = myRange.ComputeStatistics(Statistic:=wdStatisticLines) 'Returns 0
rng.MoveEnd wdCharacter, -1 
lineCount = myRange.ComputeStatistics(Statistic:=wdStatisticLines)
MsgBox "The first cell contains " & lineCount _ 
 & " lines."

Example

This example displays the number of words and characters in the first paragraph of Report.doc.

Set myRange = Documents("Report.doc").Paragraphs(1).Range 
wordCount = myRange.ComputeStatistics(Statistic:=wdStatisticWords) 
charCount = myRange.ComputeStatistics(Statistic:=wdStatisticCharacters) 
MsgBox "The first paragraph contains " & wordCount _ 
 & " words and a total of " & charCount & " characters."

See also

Range 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.