Word section character count

2006/09/12 by Lassi A. Liikkanen

Word section character count macro

With this macro you can count characters sequentially for each section of the active document. Useful for authoring structured documents that have strict boundaries for length.

VBA code

Copy and paste the code below to a new macro in VBA editor, preferably to Normal.dot

Sub SectionWordCount()
' SectionWordCount Macro
' Macro created 9/12/2006 by Lassi A. Liikkanen, 
' University of Helsinki, Cognitive Science unit
' Finland
' calculates the number of words and characters in the active document one section by the time
' based on
' http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbawd11/html/womthComputeStatistics1_HV03076775.asp
' http://support.microsoft.com/?kbid=211455
' http://support.microsoft.com/?kbid=293861

    Dim aDoc As Document
    Dim oSec As Object
    Dim NumSections As Integer
    Dim charCount, charWSCount, wordCount As Double
    'Repaginate the current document.
    Set aDoc = ActiveDocument
    'Iterate each section in the document to retrieve the words counts
    'The results are in message boxes
    NumSections = aDoc.Sections.Count
    For Each oSec In aDoc.Sections
        wordCount = oSec.Range.ComputeStatistics(Statistic:=wdStatisticWords)
        charCount = oSec.Range.ComputeStatistics(Statistic:=wdStatisticCharacters)
        charWSCount = oSec.Range.ComputeStatistics(Statistic:=wdStatisticCharactersWithSpaces)
        MsgBox 'The section ' & oSec.Index & ' contains' & vbCrLf & wordCount _
            & ' words' & vbCrLf & charCount & ' characters' & vbCrLf & charWSCount _
            & ' characters with spaces', vbOKOnly, 'Section word counter by Lassi*aL'
End Sub

Related content:
How Windows 7 restore really works, 2014/04/26

Instructions for creating bootable Windows 7 recovery environment on a USB flash device, 2014/03/30

Disabling background software installations and upgrades in Windows, 2013/03/03

No comments for this page:
Add comment | Show all comments

Your email will not be shown publicly or disclosed to third parties, it is used to validate messages
Location (City, Country):
* This information must be provided

Keywords: [windows] , [writing] Document's status: Ok (Document dates explained)

This document created: 2006/09/12
Modified: 2006/09/12
Published: (date missing / pvm. puuttuu)

This document's permanent URI (linking):

© Lassi A. Liikkanen 2006 - 2021. All rights reserved.
^Top of the Page^

*Change layout:
Printable printable
Large text


@lassial Twitter feed: