A recurring word count macro?
I managed to copy this macro from a website (forgotten which one):
Sub Section2WordCount()
' Section2WordCount Macro
' This macro counts the number of words in Section 2
' and prints it at the Bookmark named "WordCount"
' Counting is done by Format(.Sections(2).Range.ComputeStatistics(wdStat isticWords))
' which filters the command through the WordCount subroutine
Dim oRange As Word.Range
Dim sBookmarkName As String
Dim sTemp As String
sBookmarkName = "WordCount"
With ActiveDocument
sTemp = "( " + Format(.Sections(2).Range.ComputeStatistics(wdStat isticWords)) + " words)"
Set oRange = .Bookmarks(sBookmarkName).Range
oRange.Delete
oRange.InsertAfter Text:=sTemp
.Bookmarks.Add Name:=sBookmarkName, Range:=oRange
End With
End Sub
It's a really cool macro. Does anyone here know how to modify this macro so that it will do a word count for every section in a Word document and print the results at the end of the section?
Many thanks.
|