How to Get the Partial Word Count in MS Word

When you write a large number of pages in Microsoft Word, there are usually some pages at the beginning and the end of the document that are not included in the word count. For example, your boss may ask you to write a 10,000 words report. In this report, you may have to include a cover page and a Table of Contents in the beginning. After the conclusion, you may also have to add a list of references that you used in your report and a list of appendices.

In most cases, the Cover Page, Table of Contents, References, and Appendices will not be included in the Word Count. So, you need to have some mechanism, where you could get the total word count from the Introduction section to the Conclusion section only excluding the initial pages before Introduction and the final pages after the Conclusion.

Microsoft Word provides a Word Count feature in the Review Tab under the Proofing group. But pressing this option will give you the word count of the whole document. Alternatively, you can select a passage of the text and click Word Count. In this way, you will get the word count of the selected passage. But consider that you are working on a document having 100 pages. After making any changes and modifications, you will have to select from Introduction up to the Conclusion scrolling down to almost 90 pages to select the required text and know the word count.

This task can be accomplished more easily by using Visual Basic for Applications (VBA) code in Microsoft Word. There are two options to execute this task. In the first option, you should divide the document into different sections in such a way that all the pages before Introduction are in Section 1, and all the pages after Conclusion are in the last section of the report. In the second option, you need to create two bookmarks ‘Start101’ and ‘End101’. Place the bookmark ‘Start101’ before the word ‘Introduction’ and place the bookmark ‘End101’ after the last word of the conclusion. The coding for both of these options is given below. Place the codes by pressing Alt+F11 and double-clicking ThisDocument in the Project Explorer. Press F5 to execute the code.

Code for Option 1

Sub CountWords1()
    Dim oSec As Section, iWordCount, iSec As Integer
    
    For Each oSec In ThisDocument.Sections
       iSec = iSec + 1
       Select Case iSec
          Case 1, ThisDocument.Sections.Count
          Case Else
              iWordCount = iWordCount + oSec.Range.ComputeStatistics(wdStatisticWords)
       End Select
    Next
    
    MsgBox iWordCount
End Sub

Code for Option 2

Sub CountWords2()
 Dim r As Range
 Set rngStart = ActiveDocument.Bookmarks("Start101").Range
 Set rngEnd = ActiveDocument.Bookmarks("End101").Range
 Range(rngStart.Start, rngEnd.End).Select
 Set r = Selection.Range
 MsgBox r.ComputeStatistics(wdStatisticWords)
End Sub

Leave a Reply

Your email address will not be published.